How to prevent overlapping of graph lines?
21 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2020-7-14
编辑:Star Strider
2020-7-14
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 个评论
Star Strider
2020-7-15
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.
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!