yyaxis causing values on y-axes to become incorrect
4 views (last 30 days)
Show older comments
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):
:
0 Comments
Accepted Answer
Voss
on 25 Mar 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 Comments
More Answers (0)
See Also
Categories
Find more on Formatting and Annotation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!