Two Y axis plot priority
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Cameron
am 2 Mär. 2023
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';
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!