How to draw yline on yyaxis on right hand axis?

조회 수: 19 (최근 30일)
arjun luther
arjun luther 2023년 7월 21일
댓글: Star Strider 2023년 7월 23일
Hi i am trying to draw a constant line at y axis in a plot for a mean. The issue is yline functions does not plot the yline on right hand axis, does not matter how i input the argument under yyaxis right but when i input the argument under yyaxis left, it plots. Maybe there is something wrong in my code, some can point it out to me.
f6=figure
colororder({'green','red'})
yyaxis right
plot(T2_filtered,"Datetime","Global solar irradiance","LineStyle","-",'Marker','.','MarkerEdgeColor',rgb('brown'))
hold on
ax=gca % tried with and without
yline(mean(T2_filtered.("Global solar irradiance")))% also tried , calaculating mean beforehand
plot(T2_filtered,"Datetime","Emitted longwave irradiance","LineStyle","-","Marker",'.','MarkerEdgeColor',rgb('black'))
ylabel("Irradiance [W/m^2]")
yyaxis left
plot(T2_filtered,"Datetime","Reflected shortwave Irradiance",'LineStyle','-','Marker','.','MarkerEdgeColor',rgb('orange'))
plot(T2_filtered,"Datetime","Reflected Longwave irradiance",'LineStyle','-','MarkerEdgeColor','cyan',"Marker",".")
% plot(T2_filtered, "Datetime", "Aircraft Roll",'Marker','.','MarkerEdgeColor',rgb('orange'))
% plot(T2_filtered, "Datetime", "Aircraft Pitch",'Marker','.','MarkerEdgeColor','g')
% plot(T2_filtered,"Datetime", "Altitude",'Marker','|','MarkerEdgeColor',rgb('silver'))
hold off
title("Short and Long Wave Irradiance")
xlabel("Time[hh:mm:ss]")
ylabel("Irradiance [W/m^2]")
legend(Location='northoutside',NumColumns=2)
grid on
%yline(mean(T2_filtered.("Global solar irradiance"))) % this plots on left axis

채택된 답변

Star Strider
Star Strider 2023년 7월 21일
I don’t have your data, however in this simulation it seems to work correctly —
x = 0:10;
y1 = randn(size(x));
y2 = randn(size(x))*2+5;
figure
yyaxis right
plot(x, y2)
yline(2*pi,'--') % Plots Correctly W.R.T. Right 'yyaxis'
yyaxis left
plot(x, y1)
.
  댓글 수: 12
arjun luther
arjun luther 2023년 7월 22일
Thanks for your input as well as suggestions. It will get me going now. It would be really insightful if you could explain a little about this line of the code
"plot(xlim,[1 1]*mean(T2_filtered.("Global solar irradiance")), '-k')
what is happening here. How does multiplying the mean value with limits of x gets the trick done. Does xlim, [1 1] gets the whole x-axis? Thanks, once again
Star Strider
Star Strider 2023년 7월 23일
As always, my pleasure!
The plot call uses the (1x2) xlim vector (defining the limits of the x-axis) as the independent variable argument, and the (1x2) vector [1 1] that is multiplied by the value of ‘mean(T2_filtered.("Global solar irradiance"))’ as the dependent variable argument, to produce a constant horizontal line at that value. Because it uses xlim as the independent variable argument, it will automatically re-size to span the entire x-axis if the x-axis limits are changed. It defines the line style as a constant black line using the '-k' argument.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by