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!