Friday, March 18, 2005

Drawing Text in Matlab Outside of Existing Axes

If you want to draw text with Matlab outside of existing axes, you must create an invisible axes and then place visible text in it. Here is a function to do this.

function thandle = puttext(usertext, userpos, textsize)
% Textsize is as in Word, etc
% userpos is a 1x2 or 1x3 array of values where value x is 0<=x<=1
% set h0 to the handle of the current figure
h0 = gcf;
% create invisible axes to put a text control inside of
h1 = axes('Parent',h0, ...
'CameraUpVector',[0 1 0], ...
'Color','none', ...
'CreateFcn','', ...
'HandleVisibility','off', ...
'HitTest','off', ...
'Position',[0 0 1 1], ...
'Tag','ScribeOverlayAxesActive', ...
'Visible','off', ...
'XColor',[0.8 0.8 0.8], ...
'XLimMode','manual', ...
'XTickMode','manual', ...
'YColor',[0.8 0.8 0.8], ...
'YLimMode','manual', ...
'YTickMode','manual', ...
'ZColor',[0 0 0]);
% create the text control
h2 = text('Parent', h1, ...
'Color',[0 0 0], ...
'FontSize',textsize, ...
'Position',userpos, ...
'String',usertext);
% return the handle of the text control
puttext = h2;
return

No comments:

Labels

Blog Archive

Contributors