horizaontal lines in plots in a defined date

2 ビュー (過去 30 日間)
Patricia Alejandra Palacios Romero
Patricia Alejandra Palacios Romero 2018 年 7 月 4 日
回答済み: Rik 2018 年 7 月 6 日
I have a time series with dates and outflow measurements. On one hand, I have to plot them, that's not the problem; on the other hand, I need to add to that plot 2 vertical lines to indicate a range of time. I use the datetime function to put together input numbers for example datetime(2016,02,25), that represent the 2 dates for the horizontal lines.
Is there a way I can do that.?
  2 件のコメント
Rik
Rik 2018 年 7 月 4 日
In general you can plot extra lines with hold on. Tip: use ylim to figure out the extent you need to plot the lines.
Patricia Alejandra Palacios Romero
Patricia Alejandra Palacios Romero 2018 年 7 月 5 日
I already tried it but it doesn't seem to work, is there another way?

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2018 年 7 月 6 日
The code below should work for you. If it does not, please paste all red error text in a comment.
t_special=[datetime(2016,02,25) datetime(2016,03,25)];
t=datetime(2016,01,01):datetime(2016,05,01);
y=sin((1:numel(t))/10)+rand(1,numel(t))/15;
figure(1),clf(1)
plot(t,y)
hold on
y_lims=ylim;
for n=1:numel(t_special)
plot([t_special(n) t_special(n)],y_lims,'k')
end
hold off

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by