4.0

4.0 | 4 ratings Rate this file 6 Downloads (last 30 days) File Size: 2.55 KB File ID: #17151
image thumbnail

textLoc

by Ben Barrowes

 

24 Oct 2007 (Updated 25 Oct 2007)

Puts string onto the current axes with location similar to legend locations.

| Watch this File

File Information
Description

% function [H]=textLoc('string',location[,parameter,value,...])
%
% Puts string onto the current axes with location similar to legend locations.
% Passes all parameter, value pairs to text. textLoc works with semilog and
% loglog plots.
%
% H is the handle from the text command after modifications by textLoc.
%
% location can also be a 1x2 cell array containing {location,buffer} where
% buffer is a spacing buffer (in normalized units) for distance from the axes.
% buffer default is 1/50
%
% location can be any of:
% 'North' inside plot box near top
% 'South' inside bottom
% 'East' inside right
% 'West' inside left
% 'Center' centered on plot
% 'NorthEast' inside top right (default)
% 'NorthWest' inside top left
% 'SouthEast' inside bottom right
% 'SouthWest' inside bottom left
% 'NorthOutside' outside plot box near top
% 'SouthOutside' outside bottom
% 'EastOutside' outside right
% 'WestOutside' outside left
% 'NorthEastOutside' outside top right
% 'NorthWestOutside' outside top left
% 'SouthEastOutside' outside bottom right
% 'SouthWestOutside' outside bottom left
% 'NorthEastOutsideAbove' outside top right (above)
% 'NorthWestOutsideAbove' outside top left (above)
% 'SouthEastOutsideBelow' outside bottom right (below)
% 'SouthWestOutsideBelow' outside bottom left (below)
% 'Random' Random placement inside axes
% or
% 1 = Upper right-hand corner (default)
% 2 = Upper left-hand corner
% 3 = Lower left-hand corner
% 4 = Lower right-hand corner
% -1 = To the right of the plot
%
% EXAMPLES:
% figure(1); x=0:.1:10; y=sin(x); plot(x,y);
% t=textLoc('North','North')
% t=textLoc('southeastoutside',{'southeastoutside',1/20},'rotation',90)
% t=textLoc('SouthEast',4)
% t=textLoc('West',{'west',.1})
% t=textLoc('northwest',{2,.3},'Color','red')
% t=textLoc({'\downarrow','south'},'south')
% t=textLoc('SWRot',{3},'rotation',45)
% t=textLoc('NEOAbove',{'NorthEastOutsideAbove',0},'FontSize',8)
% t=textLoc('textLoc','center','edgecolor','black','fontsize',20)

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
02 Apr 2008 Bruno Silva

it would be perfect if it also had the "best" location, as in the "legend" command.

25 Aug 2008 Stephen Bocquet

A useful function, quite well thought out.

Unlike text, textLoc outputs the handle whether requested or not - I suggest fixing this by changing the output variable to Hout and including the line:
 if nargout > 0; Hout = H; end;

textLoc works as advertised for a string, but if used with a cell array it shows up a deficiency of the Matlab text function in that you can't have left-aligned text on the right hand side ('East'), or right-aligned text on the left ('West'), because the anchor point of the text object is coupled to the alignment property. The 'Extent' property could be used to position the anchor point away from the edge of the graph, but then the text won't stay in the desired position if the plot is resized. Unless the Matlab text object is revised, I can't see how to fix this problem.

16 Jun 2009 Thierry Dalon

See also FX textbp for option "best location".

30 Oct 2009 ihsan

That is what I need. Thanks!

15 Sep 2010 K E  
15 Sep 2010 K E

Useful. Along with textbp, should be a Matlab builtin.

Please login to add a comment or rating.
Updates
25 Oct 2007

better examples, more choices

Tag Activity for this File
Tag Applied By Date/Time
annotation Ben Barrowes 22 Oct 2008 09:32:47
customization Ben Barrowes 22 Oct 2008 09:32:47
text Ben Barrowes 22 Oct 2008 09:32:47
location Ben Barrowes 22 Oct 2008 09:32:47
cardinal Ben Barrowes 22 Oct 2008 09:32:47
north Ben Barrowes 22 Oct 2008 09:32:47
south Ben Barrowes 22 Oct 2008 09:32:47
east Ben Barrowes 22 Oct 2008 09:32:47
west Ben Barrowes 22 Oct 2008 09:32:47
figure Ben Barrowes 22 Oct 2008 09:32:47

Contact us at files@mathworks.com