Code covered by the BSD License  

Highlights from
TextZoomable for text that scales as you zoom

4.5

4.5 | 5 ratings Rate this file 17 Downloads (last 30 days) File Size: 2.22 KB File ID: #41513
image thumbnail

TextZoomable for text that scales as you zoom

by

 

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.

MATLAB release MATLAB 8.1 (R2013a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
10 Dec 2014 Hoi Wong

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);

19 Nov 2014 Matt J

@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.

17 Nov 2014 David

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?

27 Mar 2014 Matt J

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

27 Mar 2014 Matt J

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?

27 Mar 2014 Matt J

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

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  
18 Oct 2013 Krishnakumar  
07 Jun 2013 Simon  

Contact us