Problem with plot of one reversed bar and one standard plot

5 vues (au cours des 30 derniers jours)
Timo
Timo le 4 Jan 2018
Commenté : Timo le 12 Jan 2018
Hello everybody,
I have some problems to plot 2 graphs or in particular to display the legend of one of these graphs in an appropriate way. I have 2 parameters (discharge and precipitation) for the same time period and wanted to draw the discharge data in the "standard way" at the bottom of the plot with the associated y axis on the left side. Additionally, I wanted to sketch the precipitation data as a bar plot from the top and its corresponding y axis on the right side. My code (presented below) generally works except the fact that I only can "manually" move one of the two legends (the second legend), while the other one remains fixed and thus is located at an unfavorable point within the illustrated data. Code:
figure()
h1=axes
plot(datetime(2011,01,01):days:datetime(2014,12,31),ObsKe)
xlabel('Time Period');
ylabel('Discharge Q in [m³/s]')
legend('Qobs')
grid on
h2=axes
bar(PcpKedailyCal,2)
legend('Prec.');
set(h2,'YDir','reverse');
set(h2,'YAxisLocation','Right');
set(h2, 'Color', 'None');
set(h2, 'Xtick', []);
title('Precipitation and Discharge at Gauge Kemmern');
ylabel('Precipitation in [mm]');
If you have some general recommendations or better approaches for these kind of plots I really would appreciate it :).
Hopefully, someone can help me out.
Thanks in advance!
Greetings

Réponse acceptée

Matt Sprague
Matt Sprague le 11 Jan 2018
The legend from the first axis, h1, will not be able to be edited manually in the figure since it is no loner the current axes after h2 is created. Try adjusting its location programmatically right away when its created. This can be done through the location input ( Legend Location ) or through the Legend's Position property
  1 commentaire
Timo
Timo le 12 Jan 2018
Thanks a lot for the answer, of course you are totally right and I solved it more or less via the Location command :)
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by