View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
hline and vline

4.8 | 58 ratings Rate this file 556 Downloads (last 30 days) File Size: 3.27 KB File ID: #1039 Version: 1.0
image thumbnail

hline and vline



08 Nov 2001 (Updated )

Draws 'low-impact' horizontal or vertical lines on the current axes

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

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.


This file inspired Manual Thresholding Tool, Thresholding Tool, Improved 'Vline', Bootstrap Gait Curves, Hfill And Vfill, Advanced Hline And Vline, Mri Brain Segmentation, Demos From Image Processing Webinar 2006, and Equation Roots' Finder Graphical Solutions.

MATLAB release MATLAB 6.0 (R12)
Other requirements Tested on Win 98 and 2K. Functionality is not dependent on Matlab R12.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (66)
02 Jan 2017 Honigmelone

Why is this not part of stock Matlab?

11 Dec 2016 Michael Stritt

Thanks, I use it all the time for my work, adjusted it a little to change the thickness etc. but it's really nice

06 Dec 2016 Clemens Schlegel

Works fine but doens't work with scatterplot, only a point is drawn at the bottom when using with scatterplot.

23 Nov 2016 Lakis Katabos

16 Nov 2016 Frederico Marc

Thanks! The function is very helpful. With subplot it is not working 100% yet.

06 Nov 2016 Brij Bhushan

11 Oct 2016 Oli

Oli (view profile)

It would be nice to be able to draw black lines. Could not figure out how.
Otherwise amazing tool!

Comment only
30 Sep 2016 Geert Kapteijns

I had a problem with subscripts of labels partially disappearing into the line. Here's how I fixed it:

Comment only
31 Aug 2016 Kevin

Kevin (view profile)

07 Aug 2016 Aria Ardalan

05 Jul 2016 Mingwei Sun

23 Jun 2016 Veronika K

Great, thank you!

Comment only
06 Jun 2016 PPM

PPM (view profile)

20 May 2016 Alexander Ruesch

18 May 2016 Leandro Sousa

Very easy.
Thanks for doing this!

07 May 2016 YU GU

YU GU (view profile)

easy to use! powerful

13 Mar 2016 mima zebouchi

plz i have a probleme in sliceomatic fonction
and also Undefined function or method 'BrainPartition' for input arguments of type 'char'.

Comment only
24 Nov 2015 Daniel

Daniel (view profile)

I actually cant live without this function. It is so easy to use much easier than the alternatives.

Thanks for doing this!

26 Aug 2015 iza

iza (view profile)

any idea how to change to other segmentation algorithm ?..

Comment only
03 Feb 2015 Andy

Andy (view profile)

Very nice.

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.

08 Jun 2014 Alexander

19 Feb 2014 Adrianne

Simple and they work great.

18 Dec 2012 Yuri K

Yuri K (view profile)

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.

18 Dec 2012 Nicolas Beuchat

Nicolas Beuchat (view profile)

Use it all the time!

05 Oct 2012 bill

bill (view profile)


Comment only
11 Apr 2012 Dmitriy

22 Sep 2011 Abdullah

Exactly what I wanted !

20 Jul 2011 Tongchao

Great functions! Just what I need
It will be better if the location of text label can be arbitrarily specified.

20 Jul 2011 TAFKARS

I meant to say...very helpful tool. Slight adjustment to code wrt linewidth etc to suit my personal taste/need, otherwise good job.

22 Jun 2011 Qiang

Qiang (view profile)

05 Oct 2010 Jimmy

Jimmy (view profile)

18 Aug 2010 Matteo

Matteo (view profile)

24 Jun 2010 Akshay B

Very helpful and simple. Thanks!
I just made a minor change to the 'vline' function (to make the labels vertical):
and changed:

12 May 2010 Marit

Marit (view profile)

19 Mar 2010 John

John (view profile)

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!

Comment only
17 Mar 2010 Pete

Pete (view profile)

Quick, simple and effective. Excellent.

26 Jan 2010 Alejandro Arrizabalaga

02 Oct 2009 Kevin

Kevin (view profile)

handy little tool

08 Jul 2009 Matteo

Matteo (view profile)

21 Apr 2009 N/A

N/A (view profile)

Good job!!! Very good

21 Apr 2009 N/A

N/A (view profile)

23 Mar 2009 Storm Zhang

This really saves me a lot of time. Matlab should put these two small programs into the standard library.

14 Oct 2008 K R

Thanks - this saves a lot of time and trouble!

24 Sep 2008 B K

Great tool, thanks for submitting!

21 May 2008 Ben Kang

Very nice.

12 Nov 2007 nimat r

Thanks a lot.It's very nice.

22 Jun 2007 Greg L

Works great for linear axes. The location of the label is off if it has logrithmic axes.

09 May 2007 Josiah Haswell

Awesome! At least sizeof(long) times better than doing it the standard way.

06 Jun 2006 John D'Errico

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.

11 Apr 2006 Simon B

Great tool - one enhancement would be to allow for restricting the range of the lines.

20 Mar 2006 Felix Totir

Should be Matlab standard functions.

20 Nov 2005 carlo murgia

03 Oct 2005 Chris H

perfect for what i needed.

14 Jul 2005 Andy N.

Very Handy

11 Apr 2005 Dimitri Shvorob

When I use VLINE, and later resize the axis with AXIS, vertical line's limits remain unadjusted.

04 Feb 2005 Krishna Pillai

Nice handy function. Good job

03 Feb 2005 Min Poh


Comment only
20 Jan 2005 James Tedd

very handy

14 Jan 2005 Kedar Patel


Handy lil' time saver.

17 Nov 2004 Mike Jennings

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.

27 Oct 2004 Stephen Sester

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.

20 Oct 2004 Nahur Fonseca

thanks for writing this.
It's amazing how matlab runtime library did not have such a function built-in.

21 Sep 2004 Wolfgang Stiegmaier

Excellent, easy to use, very effective, good work!

01 Apr 2004 confidential confidential

fast and easy!

23 Jan 2004 H Z

it's very handy and useful!!! Thanks:)

16 Nov 2001 Larry Friese

Very nice, but I get two extra data elements in the plot legend? Is there a way around that?

Contact us