4.63636

4.6 | 11 ratings Rate this file 164 downloads (last 30 days) File Size: 2.47 KB File ID: #9973

GRIDXY (v2.2 feb 2008)

by Jos

 

13 Feb 2006 (Updated 18 Feb 2008)

Code covered by BSD License  

plot horizontal and vertical grid

Download Now | Watch this File

File Information
Description

GRIDXY - Plot grid lines

  GRIDXY(X) plots vertical grid lines at the positions specified by X. GRIDXY(X,Y) also plots horizontal grid lines at the positions specified by Y. GRIDXY uses the current axes, if any. Lines outside the plot area are plotted but not shown. When X or Y is empty no vertical or horizontal lines are plotted.

  The lines are plotted as a single graphics object. H = GRIDXY(..) returns a graphics handle to that line object.

  GRIDXY(..., 'Prop1','Val1','Prop2','Val2', ...) uses the properties and values specified for color, linestyle, etc. Execute GET(H), where H is a line handle, to see a list of line object properties and their current values. Execute SET(H) to see a list of line object properties and legal property values.
 
Examples
% some random plot
  plot(10*rand(100,1), 10*rand(100,1),'bo') ;
% horizontal red dashed grid
  gridxy([1.1 3.2 4.5],'Color','r','Linestyle',':') ;
% vertical solid thicker yellowish grid, and store the handle
  h = gridxy([],[2.1:0.7:5 8],'Color',[0.9 1.0 0.2],'linewidth',3) ;
 
GRIDXY can be used to plot a irregular grid on the axes.

NOTE: This file was previously known as XYREFLINE. I have changed the name to avoid a naming confusion with another function I have created.

Current version 2.2 (feb 2008)

Acknowledgements
This submission has inspired the following:
REFLINEXY
MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
16 Mar 2006 Peter Nave

Very useful!

31 Mar 2006 Alan Eskovitz

Thank you for a very useful utility. It works well in all of my applications so far.

05 Mar 2007 David Ward

Just what I needed, again a very useful script, thanks

08 Aug 2007 Abderrezak Bouchedda

very good, thanks

13 Feb 2008 Jim Gerrling

Unfortunaltely, the script plots over the Ticks and the axis (let's say you use green gridlines, they print over the ticks and axis).

13 Feb 2008 Jim Gerrling

You can fix the axis issue by
set(gca,'Layer','top')

18 Feb 2008 Jos (the author)

The 'undesired behavior' mentioned by Jim Gerrling has been fixed in v2.2

18 Mar 2008 Fred De Masi

Just what I needed, cheers

16 Apr 2008 Rhymer Yang

This is what I need!! Works very well!! Thanks a lot!!

24 Apr 2008 Mo Al Lawati

Perfect, exactly what I needed !

10 Jun 2008 Laxman P

Very nicely done. This is what should have been in matlab. Thanks for you efforts!!

03 Apr 2009 Hoi Wong

Great Program. It'd be even better if it can accept an axes handle as its first input. For the moment, since I need it in a hurry, I tapped into your code and changed this:

function hh = gridxy(hca, x,varargin)

if(isempty(hca))
hca=get(get(0,'currentfigure'),'currentaxes')
end

05 May 2009 Phil

Hello everyone,

this code is exactly what I need. Unfortunately I need it in three dimensions. Does any body have an idea?

Otherwise I will try to extend this m-file but I have a feeling that this will take me lots of time

thanks

Philipp

06 May 2009 Jos

@Phil, in 3D the lines would become planes. Is this what you want? You can also take a look at REFLINEXYZ to see if that better fills your needs:
http://www.mathworks.com/matlabcentral/fileexchange/16746

06 May 2009 Chiara

Very useful - but i'd need to add a legend with entries for the vertical bars. EG i have a histogram, and two vertical bars, say one for the mean and one for the median. How can i do this?

06 May 2009 Jos

@Chiara. You can use, e.g.,
 h(1) = gridxy(MedianValue ,'color','r')
 h(2) = gridxy(MeanValue ,'color','b')
legend(h,{'Median','Mean'})

hth
Jos

Please login to add a comment or rating.
Updates
18 Apr 2007

Name change. Add an error check for line properties

18 Feb 2008

to put gridlines behind tick marks

Tag Activity for this File
Tag Applied By Date/Time
annotation Jos 22 Oct 2008 08:15:37
customization Jos 22 Oct 2008 08:15:37
reference Jos 22 Oct 2008 08:15:37
line Jos 22 Oct 2008 08:15:37
grid Jos 22 Oct 2008 08:15:37
horizontal Jos 22 Oct 2008 08:15:37
graphics Jos 22 Oct 2008 08:15:37
vertical Jos 22 Oct 2008 08:15:37
plot Jos 24 Oct 2008 15:39:47
horizontal line Jos 24 Oct 2008 15:39:47
vertical line Jos 24 Oct 2008 15:39:47
axis Jos 24 Oct 2008 15:39:47
mark Jos 24 Oct 2008 15:39:47
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com