yyaxis causing values on y-axes to become incorrect

1 次查看(过去 30 天)
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:
Here is the result of the left y-axis, alone:
Here is the result of the right y-axis, alone:
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):
:

采纳的回答

Voss
Voss 2024-3-25
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 个评论
Aditya Khuller
Aditya Khuller 2024-3-25
Thank you both so much! I was able to adapt Adam's LimitsChangedFunction solution for my use to correct this issue :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by