File Exchange

image thumbnail

hline and vline

version 1.0 (3.27 KB) by

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

4.78462
66 Ratings

377 Downloads

Updated

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 (75)

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?

Andrei Bosco

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.

Lakis Katabos

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

Brij Bhushan

Oli

Oli (view profile)

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

Kevin (view profile)

Aria Ardalan

Mingwei Sun

Veronika K

Great, thank you!

PPM

PPM (view profile)

Leandro Sousa

Very easy.
Thanks for doing this!

YU GU

YU GU (view profile)

easy to use! powerful

mima zebouchi

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

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!

iza

iza (view profile)

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

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.

Alexander

Adrianne

Simple and they work great.

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.

Nicolas Beuchat

Nicolas Beuchat (view profile)

Use it all the time!

bill

bill (view profile)

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

Qiang (view profile)

Jimmy

Jimmy (view profile)

Matteo

Matteo (view profile)

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

Marit (view profile)

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!

Pete

Pete (view profile)

Quick, simple and effective. Excellent.

Kevin

Kevin (view profile)

handy little tool

Matteo

Matteo (view profile)

N/A

N/A (view profile)

Good job!!! Very good

N/A

N/A (view profile)

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
MATLAB 6.0 (R12)

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

» Watch video