Code covered by the BSD License  

Highlights from
TextZoomable(x,y,varargin)

4.5
4.5 | 5 ratings Rate this file 18 Downloads (last 30 days) File Size: 8.52 KB File ID: #41513 Version: 2.0
image thumbnail

TextZoomable(x,y,varargin)

by

 

26 Apr 2013 (Updated )

Text that zooms as you zoom your plot, rather than staying at a fixed font size.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

Text that zooms as you zoom your plot, rather than staying at a fixed font size. Adds text to a figure just like the text() command, except that this text grows/shrinks with figure scaling and zooming, unlike normal text that stays at a fixed font size during figure operations. Note it scales with figure height - for best scaling use 'axis equal' before setting up the text. Now revised to work with R2014b and still be backward compatible.

MATLAB release MATLAB 8.1 (R2013a)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
14 Jul 2015 Ken Purchase

Hi Matt J - thanks for letting me know. I have tried to update it - let me know if you have issues. It should now work on all versions of Matlab, but see my comments in the header of the file for a known bug.

Comment only
13 Jul 2015 Matt J

Matt J (view profile)

Hi Ken,

Unfortunately something appears to have malfunctioned with your Jan 27, 2015 update. The latest file appears to be the same as the original.

Comment only
27 Jan 2015 Ken Purchase

Revised, with many thanks to the Matlab User
Community, including Matt J, Hoi Wong, Philip Caplan.

Comment only
10 Dec 2014 Hoi Wong

Hoi Wong (view profile)

TMW's support really go the extra mile helping its customers. With the help of Philip Caplan, the last bit of the puzzle to get this to work on R2014b's new graphic system is solved.

Replace:
hgp = findpackage('hg');
axesC = findclass(hgp,'axes');
LimListener = handle.listener(imAxes,[axesC.findprop('XLim') axesC.findprop('YLim')],...
'PropertyPostSet',@localLimitListener);

With:
LimListener = addlistener(imAxes,{'XLim','YLim'},'PostSet',@localLimitListener);

Comment only
19 Nov 2014 Matt J

Matt J (view profile)

@David,
I believe the particular error you mention is fixable by changing that line as follows

PostPositionListener = addlistener(hFig,'SizeChanged',...
@(o,e) localPostPositionListener(o,e,imAxes) );

See also the following thread in MATLAB Answers,

<http://www.mathworks.com/matlabcentral/answers/163280-addlistener-syntax-not-recognized-in-r2014b>

However, I'm afraid that even after fixing that, I am finding further problems running TextZoomable in R2014b. In particular, the following lines use undocumented functions findpackage and findclass,

hgp = findpackage('hg');
axesC = findclass(hgp,'axes');

whose behavior has changed somehow.

Comment only
17 Nov 2014 David

David (view profile)

I'm trying to use your code with R2014b and I get this error:
No method 'addlistener' with matching signature found for class 'matlab.ui.Figure'.

I've run the script provided by Mathworks to update code for the new graphics system and it changed one line, but it still doesn't work. Any ideas?

Comment only
27 Mar 2014 Matt J

Matt J (view profile)

Here's a better version of the DeleteFcn,

function DeleteMethod(src,event)
% when called, rescale all fonts in image
hAx=gca;
hFig = get(hAx,'Parent');
ud=get(hAx, 'UserData');
idx=(ud.handles==src);

ud.ratios(idx)=[];
ud.handles(idx)=[];



if isempty(ud.handles)
setappdata(hFig,'KenAxeResizeListeners',[]);
set(hAx, 'UserData',[]);
else
set(hAx, 'UserData',ud);
end

delete(src);

end

Comment only
27 Mar 2014 Matt J

Matt J (view profile)

Ken,

There seems to be a duplicate of this submission at

http://www.mathworks.com/matlabcentral/fileexchange/41501-textzoomable-for-text-that-scales-as-you-zoom

Which is the most official/current version? Also, when I do a very high zoom on the text, parts of the text appear outside the axes. Is there a way to prevent this, i.e., so that only text within the window of the axes is visible?

Comment only
27 Mar 2014 Matt J

Matt J (view profile)

I get the same errors/warnings as Nispio, but setting txtHandle's DeleteFcn callback to the following seems to fix it.

function DeleteMethod(src,event)
% when called, rescale all fonts in image
hAxes=gca;
hFig = get(hAxes,'Parent');
setappdata(hFig,'KenAxeResizeListeners',[]);
set(hAxes, 'UserData',[]);
delete(src);
end

04 Nov 2013 Nispio

Nispio (view profile)

This gives the following warnings/errors whenever I try to plot over the top of my old plot.

Warning: Error occurred while evaluating listener callback.
> In axis>LocSetTight1 at 332
In axis>LocSetTight at 277
In axis>LocSetImage at 414
In axis at 135
In showimage at 5
Attempt to reference field of non-structure array.

Error in TextZoomable>getBestFontSize (line 70)
fs = round(ud.ratios * hFigFactor / axHeight);

Error in TextZoomable>localLimitListener (line 106)
fs = getBestFontSize(imAxes);

04 Nov 2013 Nispio

Nispio (view profile)

 
18 Oct 2013 Krishnakumar  
07 Jun 2013 Simon

Simon (view profile)

 
Updates
27 Jan 2015 1.1

Revised to work with R2014b and still be backward compatible.

14 Jul 2015 2.0

Trying to re-upload the changes from earlier this year, which didn't seem to update properly on the File Exchange.

Contact us