These functions draw horizontal or vertical lines at specified places on the current axes. The axes are automatically held for the drawing of the lines, and restored to their previous 'hold' states afterwards. THe HandleVisibility of the new lines is "off" so that they don't appear on legends. (Incidentally, this also makes them invisible to moveplot.m and addplot.m) Objects with HandleVisibility set to off can be "found" by setting the root object's "ShowHiddenHandles" property to "on". Also, if an output argument is specified, the function will return the handle to the otherwise 'hidden' object.
Further arguments allow the user to set the linetype and color of the line (default is 'r:'), and to add labels. For example:
h = vline(42,'g','The Answer')
will return a handle to a vertical line at x=42 on the current axes, colored green, and with a text label "The Answer" on the axes close to the line, and in the same color of the line.
hline and vline both accept vector inputs.
Brandon Kuczenski (2021). hline and vline (https://www.mathworks.com/matlabcentral/fileexchange/1039-hline-and-vline), MATLAB Central File Exchange. Retrieved .
is it possible to add a "delta" as input in order to shift the position of the text on the y axis ?
I am trying to use it on subplot of loglog plot using tight_subplot function, but the actual vline text position is shifted in x for unknown reason (probably due to tight_subplot). I add 2 vlines at different x position, but the text of those 2 vlines are surimposed. So I think that adding a delta as input such as hhh=vline(x,in1,in2,delta), can help to shift or not (delta=0) the position of the annotation.
I am using Matlab 2016b (and I know that from 2018, there is a function in Matlab for this but I don't have recent version)
% Example of code modification of vline :
text(x+1e-2*xrange,delta + y(1)+ 0.1*(y(2)-y(1)),label,'color',get(h,'color'))
text(x-5e-2*xrange,delta + y(1)+0.1*(y(2)-y(1)),label,'color',get(h,'color'))
very useful! thanks
Excellent. Thank you!
Doesn't plot full length of graph, no clue why. Simpler to just use plot(xlim,[0,0],HandleVisibility,'off')
Thank you so much! It was very helpful.
To the people who wish it could do different line widths: an easy solution is to go to line 84 and add 'linewidth',2) arguments to the plot command. A non-hardcoded solution would be to add a variable to the function, "LW" and then adjust the cases (because nargin changes) and put that variable in the 84th line where the plot is called
Great simplification. Thanks!!
Work well thanks
Cannot use latex interpreter in label
very helpful!! Wish having a new version of line RGB-color enable. thanks!
Nice and efficient!
Thanks a lot
Is it possible to change the size of the text?
Thanks, you make my day!!
I required a lot of lines on my graph, the labels overlap each other. Any fix to this?
Why is this not part of stock Matlab?
Thanks, I use it all the time for my work, adjusted it a little to change the thickness etc. but it's really nice
Works fine but doens't work with scatterplot, only a point is drawn at the bottom when using with scatterplot.
Thanks! The function is very helpful. With subplot it is not working 100% yet.
It would be nice to be able to draw black lines. Could not figure out how.
Otherwise amazing tool!
I had a problem with subscripts of labels partially disappearing into the line. Here's how I fixed it:
Great, thank you!
Thanks for doing this!
easy to use! powerful
plz i have a probleme in sliceomatic fonction
and also Undefined function or method 'BrainPartition' for input arguments of type 'char'.
I actually cant live without this function. It is so easy to use much easier than the alternatives.
Thanks for doing this!
any idea how to change to other segmentation algorithm ?..
Only issue is that the line is only applied within the visible axes. For example I am applying the line within a GUI, if you zoom out of the plot then you need to reapply.
Simple and they work great.
It would be nice to be able to use parameter name-value pairs as for line objects. For example, I often need 'LineWidth'. Can do it as a separate set statement, but one-liner would be better.
Use it all the time!
Exactly what I wanted !
Great functions! Just what I need
It will be better if the location of text label can be arbitrarily specified.
I meant to say...very helpful tool. Slight adjustment to code wrt linewidth etc to suit my personal taste/need, otherwise good job.
Very helpful and simple. Thanks!
I just made a minor change to the 'vline' function (to make the labels vertical):
I could not find these two in the Matlab stand function list. They are handy and should be standard functions. Any one know the reason why NOT? Excellent job, Brandon!
Quick, simple and effective. Excellent.
handy little tool
Good job!!! Very good
This really saves me a lot of time. Matlab should put these two small programs into the standard library.
Thanks - this saves a lot of time and trouble!
Great tool, thanks for submitting!
Thanks a lot.It's very nice.
Works great for linear axes. The location of the label is off if it has logrithmic axes.
Awesome! At least sizeof(long) times better than doing it the standard way.
Very nice. My only (minor) comment would be it might be nice to control the location of the annotation text. I do agree that this is functionality that should have always been in matlab.
By the way, if anyone is worried, it works on a mac also. This is not system specific code.
Great tool - one enhancement would be to allow for restricting the range of the lines.
Should be Matlab standard functions.
perfect for what i needed.
When I use VLINE, and later resize the axis with AXIS, vertical line's limits remain unadjusted.
Nice handy function. Good job
Handy lil' time saver.
This is an excellent, easy to use tool to add a reference line in your plot figure. Can also be customized for color and linetypes. Good Job.
This function meets the common need for drawing simple horz and vert lines on plots. Very nice addition to my tools; should be incorporated into future plot revision. Thank you for taking the time to share your work.
thanks for writing this.
It's amazing how matlab runtime library did not have such a function built-in.
Excellent, easy to use, very effective, good work!
fast and easy!
it's very handy and useful!!! Thanks:)
Very nice, but I get two extra data elements in the plot legend? Is there a way around that?
Inspired: Equation Roots' Finder-Graphical Solutions, MRI Brain Segmentation, Thresholding Tool, Demos from Image Processing Webinar 2006, Advanced hline and vline, Manual Thresholding Tool, Improved 'vline', hfill and vfill, Bootstrap Gait Curves
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!