Problem with plot of one reversed bar and one standard plot

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Matt Sprague
Matt Sprague il 11 Gen 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 Commento
Timo
Timo il 12 Gen 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!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by