Vertical lines with text in plot
Mostra commenti meno recenti
Hello everybody
I have created a plot in Matlab. Let's assume for simplicity that I have the following plot:
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
Now I would like to add vertical lines (going from the bottom of the figure to the top) at positions x = 1, x = 3 and x = 5. Additionally, the vertical lines should have text (next to the line or on top of the line). For example, for the line at x = 1 I would like to have the text "test 1".
How can this be done? This seems to be a pretty tricky thing in Matlab.
1 Commento
Jan
il 27 Set 2017
From the bottom of the figure to the top, or from the axes?
Risposta accettata
Più risposte (1)
Jan
il 27 Set 2017
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y);
hold('on');
line([1 3 5; 1 3 5], [-10, -10, -10; 10, 10, 10], 'YLimInclude', 'off');
text([1 3 5], [1, 1, 1], {'Test 1', 'Test 2', 'Test 3'}, ...
'VerticalAlignment', 'top')
Disabling 'YLimInclude' let the Y-limits untouched by this object. Then you can even Zoom in the diagram without seeing the end of the line (at least until a certain level). Unfortunately YLimInclude is undocumented, but it works for many years now.
1 Commento
Yair Altman
il 17 Ott 2017
Here is the unofficial documentation for the undocumented YLimInclude property: http://undocumentedmatlab.com/blog/plot-liminclude-properties
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!