Creating Plot with 2 Y-Axis

12 ビュー (過去 30 日間)
Georg Reising
Georg Reising 2023 年 1 月 26 日
回答済み: Les Beckham 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 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