File Exchange

image thumbnail

hline and vline

version 1.0.0.0 (3.27 KB) by Brandon Kuczenski
Draws 'low-impact' horizontal or vertical lines on the current axes

347 Downloads

Updated 09 Nov 2001

View License

Editor's Note: This file was a File Exchange Pick of the Week

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.

Comments and Ratings (124)

jgomz

Excellent. Thank you!

Doesn't plot full length of graph, no clue why. Simpler to just use plot(xlim,[0,0],HandleVisibility,'off')

Super awesome!

Eva

Thank you so much! It was very helpful.

tanveer haq

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!!

Ramez hamid

Thanks

Shay Moshe

M. Saad

Thanks alot

Oleg Boiko

Work well thanks

Sen ZHAO

Cannot use latex interpreter in label

Bucks Lin

very helpful!! Wish having a new version of line RGB-color enable. thanks!

contnoel

Josh Beers

Yuanqi Wang

Nice and efficient!

Taotao Zhou

jk_cau

Thanks a lot

Is it possible to change the size of the text?

Thanks, you make my day!!

julen otegi

Paul Kane

Jin Tan

Misaki Soma

I required a lot of lines on my graph, the labels overlap each other. Any fix to this?

Honigmelone

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.

Oli

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:

https://gist.github.com/Kappie/20a296e1d78b0db6364c59af22d595f3

Kevin

Mingwei Sun

Veronika K

Great, thank you!

PPM

Very easy.
Thanks for doing this!

YU GU

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'.

Daniel

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

Thanks for doing this!

iza

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

Andy

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.

Alexander

Adrianne

Simple and they work great.

Yuri K

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!

bill

nice

Dmitriy

Abdullah

Exactly what I wanted !

Tongchao

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

TAFKARS

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

Qiang

Jimmy

Matteo

Akshay B

Very helpful and simple. Thanks!
I just made a minor change to the 'vline' function (to make the labels vertical):
Changed:
text(x+0.01*xrange,y(1)+0.1*(y(2)-y(1)),label,'color',get(h,'color'))
to:
text(x+0.02*xrange,y(1)+0.1*(y(2)-y(1)),label,...
'color',get(h,'color'),'Rotation',90)
and changed:
text(x-.05*xrange,y(1)+0.1*(y(2)-y(1)),label,'color',get(h,'color'))
to:
text(x-.01*xrange,y(1)+0.1*(y(2)-y(1)),label,...
'color',get(h,'color'),'Rotation',90)

Marit

John

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!

Pete

Quick, simple and effective. Excellent.

Kevin

handy little tool

Matteo

N/A

Good job!!! Very good

N/A

Storm Zhang

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

K R

Thanks - this saves a lot of time and trouble!

B K

Great tool, thanks for submitting!

Ben Kang

Very nice.

nimat r

Thanks a lot.It's very nice.

Greg L

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

Josiah Haswell

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

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.

Simon B

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

Felix Totir

Should be Matlab standard functions.

carlo murgia

Chris H

perfect for what i needed.

Andy N.

Very Handy

Dimitri Shvorob

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

Krishna Pillai

Nice handy function. Good job

Min Poh

test

James Tedd

very handy

Kedar Patel

Thanks!

Handy lil' time saver.

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.

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.

Nahur Fonseca

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

Wolfgang Stiegmaier

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

confidential confidential

fast and easy!

H Z

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

Larry Friese

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

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux