How to prevent overlapping of graph lines?

43 ビュー (過去 30 日間)
Noi Sekuri
Noi Sekuri 2020 年 7 月 14 日
コメント済み: Star Strider 2020 年 7 月 15 日
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)

回答 (1 件)

Star Strider
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 件のコメント
Noi Sekuri
Noi Sekuri 2020 年 7 月 15 日
Thank you very much but I am looking for a way to plot them without using semilogy.
Star Strider
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 Exchange2-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