How to prevent overlapping of graph lines?
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I want to plot (x,y1), (x,y2) and (x,y3) on the same graph where
x = [20000, 40000, 60000, 80000, 100000]
y1 = [100232986, 397895944, 900510601, 1597421811, 2494526740]
y2 = [260952, 561980, 877225, 1203434, 1536068]
y3 = [359227, 716397, 1088346, 1580845, 1997379]
However, when I plot these on the same graph its very difficult to distinguish between (x,y2) and (x,y3). They look as if they overlap. How can I make all of them visible (no overlapping)? They have to be on the same graph and I dont want to use semilogy. I want all of them to look like increasing functions as they are.
The code I used:
x = [20000, 40000, 60000, 80000, 100000]
y1 = [100232986, 397895944, 900510601, 1597421811, 2494526740]
y2 = [260952, 561980, 877225, 1203434, 1536068]
y3 = [359227, 716397, 1088346, 1580845, 1997379]
plot(x,y1)
hold on
plot(x,y2)
hold on
plot(x,y3)
0 comentarios
Respuestas (1)
Star Strider
el 14 de Jul. de 2020
Editada: Star Strider
el 14 de Jul. de 2020
Use a logarithmic y-axis:
x = [20000, 40000, 60000, 80000, 100000];
y1 = [100232986, 397895944, 900510601, 1597421811, 2494526740];
y2 = [260952, 561980, 877225, 1203434, 1536068];
y3 = [359227, 716397, 1088346, 1580845, 1997379];
figure
semilogy(x,y1)
hold on
plot(x,y2)
plot(x,y3)
hold off
grid
legend('y_1', 'y_2', 'y_3', 'Location','E')
producing:
EDIT — (14 Jul 2020 at 20:36)
Added plot image.
.
2 comentarios
Star Strider
el 15 de Jul. de 2020
My pleasure.
Note that they do not ‘overlap’. They have such significantly different amplitudes (on the order of ) that the ordinary linear scaling prevents ‘y2’ and ‘y3’ from being distinguished from 0.
The only other option I can offer is:
figure
yyaxis left
plot(x,y1)
yyaxis right
plot(x,y2)
hold on
plot(x,y3)
hold off
grid
legend('y_1', 'y_2', 'y_3', 'Location','E')
producing:
The yyaxis function was introduced in R2016a. If you have an earlier release, use plotyy instead (with different code).
Another option is to plot each one in a subplot or stackedplot (R2018b and later), however I got the impression that you wanted them plotted on the same axes.
.
Ver también
Categorías
Más información sobre Line 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!