hold on y-axis

5 次查看(过去 30 天)
GIOVANNA GUADAGNIN
GIOVANNA GUADAGNIN 2021-5-11
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--')

类别

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