What is the best way to fill the areas between lines in a graph?

56 次查看(过去 30 天)
I have to plot a the wave patterns in a nozzle and I want to highlight the changes with filling the areas between the lines with color but I can't find a way to do this.

采纳的回答

Image Analyst
Image Analyst 2015-4-23
How about using patch() or fill()? Or you can use area() if you plot the top curve first and they don't overlap any.

更多回答(2 个)

Image Analyst
Image Analyst 2015-4-24
HC, I haven't heard from you so I guess you must be having trouble. Here is a demo:
curve1 = 10 + randi(2, 1, 20);
curve2 = 1 + randi(2, 1, 20);
% Find area coordinates.
inBetweenRegionX = [1:length(curve1), length(curve2):-1:1]
inBetweenRegionY = [curve1, fliplr(curve2)];
% Display the area first so it will be in the background.
fill(inBetweenRegionX, inBetweenRegionY, 'g');
hold on;
% Now plot the curves and markers on top of the area.
plot(curve1, 'rd-', 'LineWidth', 3);
plot(curve2, 'bs-', 'LineWidth', 3);
grid on;
ylim([0,13]);
If this meets your needs, please mark it as Accepted. Thanks in advance.
  5 个评论
Image Analyst
Image Analyst 2023-5-18
@Stefan Rather than hijack @HC's question (even though your question is related), could you please start your own new question?

请先登录,再进行评论。


Amy Farris
Amy Farris 2018-3-13
Thank you so much for this answer! It was very helpful to me!!!

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by