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 Center および File ExchangeGrid 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