Problem with plot of one reversed bar and one standard plot
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Matt Sprague
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!