Two Y axis plot priority

조회 수: 5 (최근 30일)
B R
B R 2023년 3월 2일
편집: Voss 2023년 3월 2일
I am trying to create a plot with two vertical axes, in which the line associated with the left vertical axis is plotted OVER the line associated with the right vertical axis. How do I bring the line associated with the left vertical axis to the front?
Sample Code:
x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = cos(x);
figure, plot(x,y1,'linewidth',3) % Large linewidth so you can see which line is in front
yyaxis right, plot(x,y2,'linewidth',3)
Thanks.

채택된 답변

Cameron
Cameron 2023년 3월 2일
There's no great way to do it. You have to trick the plot into thinking there is Z data.
x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = cos(x);
fig = figure;
ax = axes(fig);
yyaxis left
p1 = plot(x,y1,'linewidth',3); % Large linewidth so you can see which line is in front
yyaxis right
p2 = plot(x,y2,'linewidth',3);
p1.ZData = ones(length(p1.YData),1);
p2.ZData = zeros(length(p1.YData),1);
ax.SortMethod = 'depth';
  댓글 수: 1
B R
B R 2023년 3월 2일
Ok, great. Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by