Problem with plot of one reversed bar and one standard plot

조회 수: 5 (최근 30일)
Timo
Timo 2018년 1월 4일
댓글: Timo 2018년 1월 12일
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

채택된 답변

Matt Sprague
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
  댓글 수: 1
Timo
Timo 2018년 1월 12일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by