What is the best way to fill the areas between lines in a graph?
56 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
HC
el 23 de Abr. de 2015
Comentada: Stefan
el 18 de Mayo de 2023
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.
0 comentarios
Respuesta aceptada
Image Analyst
el 23 de Abr. de 2015
How about using patch() or fill()? Or you can use area() if you plot the top curve first and they don't overlap any.
0 comentarios
Más respuestas (2)
Image Analyst
el 24 de Abr. de 2015
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.
Amy Farris
el 13 de Mzo. de 2018
Thank you so much for this answer! It was very helpful to me!!!
1 comentario
Image Analyst
el 14 de Mzo. de 2018
You're welcome. If it solved your problem, please mark it as Accepted. Thanks in advance.
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!