Code covered by the BSD License  

Highlights from
offsetPlot

offsetPlot

by

 

offsetPlot is a function that relabels the axes relative to the minimum (x,y) coordinates

offsetPlot(plotHandle, labelPrecision, addOriginText )
%% function origin = offsetPlot(plotHandle, labelPrecision, addOriginText )
% This function takes an existing plot's handle, plotHandle, and replaces 
% the tick labels with values relative to the plot origin.  
% The optional second input allows the user to adjust the precision of the 
% labels and a third optional input argument displays the origin as a 
% text label on the plot. 
% The function returns the x,y coordinates of the origin.

% INPUTS
%  plotHandle - handle for existing plot
%  labelPrecision (default = 3) - number of digits desired in labels
%  addOriginText (default = 0) - flag whether origin should be labelled
%
% author: William Buller, wtbuller@mtu.edu

function origin = offsetPlot(plotHandle, labelPrecision, addOriginText )

if(nargin < 2) 
	labelPrecision = 3;
end
if(nargin < 3) 
	addOriginText = 0;
end

x0 = xlim;
y0 = ylim;

origin = [ x0(1), y0(1) ];

xgt = get(gca, 'xtick');
ygt = get(gca, 'ytick');

if( length(unique(diff(xgt))) == 1 )
	xtx = linspace( 0, diff(x0), length(xgt) )';
else
	xtx = logspace( 0, diff(x0), length(xgt) )';
end

if( length(unique(diff(ygt))) == 1 )
	ytx = linspace( 0, diff(y0), length(ygt) )';
else
	ytx = logspace( 0, diff(y0), length(ygt) )';
end

xtL = num2str(xtx,labelPrecision);
ytL = num2str(ytx,labelPrecision);

set( plotHandle, 'XTickLabel', xtL );
set( plotHandle, 'YTickLabel', ytL );

if( addOriginText == 1 )
	orstr = ['origin: (', num2str(origin(1),labelPrecision), ', ', num2str(origin(2),labelPrecision), ')'];
	text( xgt(1), ygt(1), orstr, 'BackgroundColor', [1 1 0], 'fontsize', 12 );
end

Contact us