Creating Plot with 2 Y-Axis
조회 수: 3 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!