yyaxis causing values on y-axes to become incorrect
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aditya Khuller
el 25 de Mzo. de 2024
Comentada: Aditya Khuller
el 25 de Mzo. de 2024
I am trying to create a plot with two y-axes. My goal is to show 4 lines, but two axes. The values of both axes are related,
I used yyaxis, but when I do, the values on the right y-axis are no longer correct. Can you please help me find the bug?
Here is the code I used:
figure;
yyaxis left
hold on;
xlabel('3-m Air Temperature (K)');
ylabel('Sublimation Rate (cm yr^{-1})');
plot(Theta2_warm,dzdt_DB_warm_high_wind,'k','LineWidth',3,'LineStyle','-');
plot(Theta2_warm,dzdt_warm_high_wind,'Color',[0.4940 0.1840 0.5560],'LineWidth',3,'LineStyle','-');
plot(Theta2_warm,dzdt_DB_warm_low_wind,'k','LineWidth',3,'LineStyle','--');
plot(Theta2_warm,dzdt_warm_low_wind,'Color',[0.4940 0.1840 0.5560],'LineWidth',3,'LineStyle','--');
ylim([0 4500])
set(gca,'YColor','k');
yyaxis right
ylabel('H_L (W m^{-2})')
plot(Theta2_warm,LE_DB_forced_warm_high_wind+LE_DB_free_warm_high_wind,'k','LineWidth',3,'LineStyle','none');
plot(Theta2_warm,LE_warm_high_wind,'Color',[0.4940 0.1840 0.5560],'LineWidth',3,'LineStyle','none');
plot(Theta2_warm,LE_DB_forced_warm_low_wind+LE_DB_free_warm_low_wind,'k','LineWidth',3,'LineStyle','none');
plot(Theta2_warm,LE_warm_low_wind,'Color',[0.4940 0.1840 0.5560],'LineWidth',3,'LineStyle','none');
set(gca,'YColor','k');
set(gca,'FontSize',18)
Here is the result:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1650486/image.png)
Here is the result of the left y-axis, alone:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1650491/image.png)
Here is the result of the right y-axis, alone:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1650496/image.png)
At 240 K, the black and purple solid lines are ~1690 and 1620 for the right y-axis. But in the combined plot above, they are lower for some reason. I also tried removing the ylim statement, but the result is stil incorrect in the combined plot (the plot is showing that H_L is 2000 for some reason):
:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1650501/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1650501/image.png)
0 comentarios
Respuesta aceptada
Voss
el 25 de Mzo. de 2024
The lines corresponding to the right y-axis are all plotted with LineStyle 'none' and no marker, so they don't appear at all. In other words, you are plotting 8 lines, but you only see 4, because the other 4 have no line and no markers.
5 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Formatting and Annotation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!