Creating Plot with 2 Y-Axis

3 次查看(过去 30 天)
Georg Reising
Georg Reising 2023-1-26
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?

回答(1 个)

Les Beckham
Les Beckham 2023-1-26
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

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by