Two Y axis plot priority
조회 수: 5 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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';
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!