hold on y-axis

조회 수: 6 (최근 30일)
GIOVANNA GUADAGNIN
GIOVANNA GUADAGNIN 2021년 5월 11일
댓글: GIOVANNA GUADAGNIN 2021년 5월 16일
i want to plot axes parallel to y-axis. I got the limits for y easily and
on the x-axis I have dates like '2020-11-17 13:03:00'.
this is my plot
figure
yyaxis left
plot(T.UTC_Date___Time,mareaCM,'b--');
ylim
yyaxis right
plot(T.UTC_Date___Time,T.DissolvedOxygenSaturation,'r--');
hold on
%I tried with this but it doesn't work
plot([2020-11-17 13:03:00 2020-11-17 13:03:00],[0 450],'g--')
  댓글 수: 1
Andy
Andy 2021년 5월 13일
Do any error messages appear or is it that Matlab doesn't report a problem but the line doesn't appear where you think it should?

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

답변 (1개)

Steven Lord
Steven Lord 2021년 5월 13일
%I tried with this but it doesn't work
% plot([2020-11-17 13:03:00 2020-11-17 13:03:00],[0 450],'g--')
No, that's not going to do what you expected. If you want to plot using date and time data on the X axis, turn that data into a datetime array first.
s = ['2020-11-17 13:03:00'; '2020-11-17 13:03:00']
s = 2×19 char array
'2020-11-17 13:03:00' '2020-11-17 13:03:00'
dt = datetime(s)
dt = 2×1 datetime array
17-Nov-2020 13:03:00 17-Nov-2020 13:03:00
In this case using the xline function is probably what you want instead of plotting using the same X values twice. That will keep the line spanning the whole height of the axes even if you pan or change the Y axis limits.
xline(dt(1), 'g--')
  댓글 수: 1
GIOVANNA GUADAGNIN
GIOVANNA GUADAGNIN 2021년 5월 16일
thank you!

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

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by