필터 지우기
필터 지우기

Drawing Vertical Lines in a datetime plot

조회 수: 6 (최근 30일)
Rainer
Rainer 2016년 12월 29일
답변: Walter Roberson 2016년 12월 29일
Executing the script below gives a nice graph.
x = datetime({'2014-05-25';'2014-05-26';'2014-05-27';'2014-05-28';'2014-05-29'});
y=[130, 135, 120, 130, 130];
plot(x,y);
Now, I want vertical lines on certain days to mark events. How can I do this?

채택된 답변

Star Strider
Star Strider 2016년 12월 29일
Here is how I did it a few days ago in my Answer to a similar Question:
% Make example time series data
t = datetime(2014,6,28) + calweeks(0:9);
y = rand(1,10);
plot(t,y); % Plot time series data
hold on;
tMark = datetime(2014,8,1); % Time to mark by a vertical line
plot([tMark tMark], ylim);
You can easily adapt this to your reuqirements.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 12월 29일
YL = reshape(get(gca, 'YLim'), [], 1);
which_day = reshape(x([2 4]), 1, []);
hold on
plot([which_day; which_day], repmat(YL, 1, length(which_day)))
hold off

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by