How to prevent overlapping of graph lines?

조회 수: 41 (최근 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 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