1 function hh = gridxy(x,varargin)
2 % GRIDXY - Plot grid lines
3 % GRIDXY(X) plots vertical grid lines at the positions specified
4 % by X. GRIDXY(X,Y) also plots horizontal grid lines at the positions
5 % specified by Y. GRIDXY uses the current axes, if any. Lines outside
6 % the plot area are plotted but not shown. When X or Y is empty no vertical
7 % or horizontal lines are plotted.
9 % The lines are plotted as a single graphics
object. H = GRIDXY(..) returns
10 % a graphics handle to that line
object.
12 % GRIDXY(..., 'Prop1','Val1','Prop2','Val2', ...) uses the properties
13 % and values specified for color, linestyle, etc. Execute GET(H), where H is
14 % a line handle, to see a list of line
object properties and their current values.
15 % Execute SET(H) to see a list of line
object properties and legal property values.
19 % plot(10*rand(100,1), 10*rand(100,1),'bo') ;
20 % % horizontal red dashed grid
21 % gridxy([1.1 3.2 4.5],'Color','r','Linestyle',':') ;
22 % % vertical solid thicker yellowish grid, and store the handle
23 % h = gridxy([],[2.1:0.7:5 8],'Color',[0.9 1.0 0.2],'linewidth',3) ;
25 % GRIDXY can be used to plot a irregular grid on the axes.
27 % See also PLOT, REFLINE, GRID, AXES, REFLINEXY
29 % NOTE: This function was previously known as XYREFLINE
32 % version 2.2 (feb 2008)
33 % (c) Jos van der Geest
37 % Created (1.0) feb 2006
38 % 2.0 apr 2007 - renamed from reflinexy to gridxy, reflinexy is now used
39 % for plotting intersection between X and Y axes
40 % 2.1 apr 2007 - add error check for line properties
41 % 2.2 feb 2008 - added set(gca,'layer','top') to put gridlines behind the
48 error('Numeric argument expected') ;
57 % optional arguments are
59 elseif isnumeric(va{1})
63 error(
'Invalid second argument') ;
65 if mod(size(va),2) == 1,
66 error(
'Property-Value have to be pairs') ;
70 %
get the axes to plot in
71 hca=
get(
get(0,
'currentfigure'),
'currentaxes');
73 warning(
'No current axes found') ;
77 %
get the current limits of the axis
78 % used
for limit restoration later on
79 xlim =
get(hca,
'xlim') ;
80 ylim =
get(hca,
'ylim') ;
82 % setup data
for the vertical lines
83 xx1 = repmat(x(:).
',3,1) ; 84 yy1 = repmat([ylim(:) ; nan],1,numel(x)) ; 86 % setup data for the horizontal lines 87 xx2 = repmat([xlim(:) ; nan],1,numel(y)) ; 88 yy2 = repmat(y(:).',3,1) ;
91 % create data
for a single line
object 95 % add the line to the current axes
96 np =
get(hca,
'nextplot') ;
97 set(hca,
'nextplot',
'add') ;
98 h = line(
'xdata',xx1(:),
'ydata',yy1(:)) ;
99 set(hca,
'ylim',ylim,
'xlim',xlim) ; % reset the limits
101 uistack(h,
'bottom') ; % push lines to the bottom of the graph
102 set(hca,
'nextplot',np,
'Layer',
'top') ; % reset the nextplot state
106 set(h,va{:}) ; %
set line properties
109 error(msg.message(21:end)) ;
117 if nargout==1, %
if requested
return handle