Problem with plot of one reversed bar and one standard plot
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt Sprague
2018-1-11
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!