Drawing Vertical Lines in a datetime plot
Show older comments
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?
Accepted Answer
More Answers (1)
Walter Roberson
on 29 Dec 2016
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
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!