Creating Plot with 2 Y-Axis

12 vues (au cours des 30 derniers jours)
Georg Reising
Georg Reising le 26 Jan 2023
Hey, I'm always creating plots over the plot menu. Therefore, I export data as column vectors in my workspace and then I'm adding several data in one line plot. I now have 2 graphs in my plot, but I would like to add a second y axis on the right side. I know, there is the yyaxis command, but is there a way, to add a second y axis over the Property Inspector? Or somehow else, without using any command/code?

Réponses (1)

Les Beckham
Les Beckham le 26 Jan 2023
No there is no way to do that without some manual coding (if only on the command line). But it isn't hard. Here's a simple example.
t = linspace(0, 4*pi, 200);
x = sin(t);
y = 10*cos(t);
If you select t, then x, then y in the Workspace window and click the second plot option in the Plot toolbar, it executes the following code (you will see it in the Command window.
plot(t,x,'DisplayName','x');hold on;plot(t,y,'DisplayName','y');hold off;
grid on % << I added this because I like the grid
Now, if I want two y axes instead since the amplitude of one signal is so much smaller than the other one, I can just change that line of code a little bit:
figure
yyaxis left;plot(t,x,'DisplayName','x');yyaxis right;plot(t,y,'DisplayName','y');
grid on
legend % << I like legends also

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by