How to prevent overlapping of graph lines?

21 Ansichten (letzte 30 Tage)
Noi Sekuri
Noi Sekuri am 14 Jul. 2020
Kommentiert: Star Strider am 15 Jul. 2020
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)

Antworten (1)

Star Strider
Star Strider am 14 Jul. 2020
Bearbeitet: Star Strider am 14 Jul. 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 Kommentare
Noi Sekuri
Noi Sekuri am 15 Jul. 2020
Thank you very much but I am looking for a way to plot them without using semilogy.
Star Strider
Star Strider am 15 Jul. 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.
.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by