File Exchange

image thumbnail


version 2.0 (8.52 KB) by

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



View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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.

Comments and Ratings (13)

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.

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.

Ken Purchase

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

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.

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

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

Matt J

Matt J (view profile)

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,


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.


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?

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
    hFig = get(hAx,'Parent');
    ud=get(hAx, 'UserData');
       if isempty(ud.handles)
          set(hAx, 'UserData',[]);
          set(hAx, 'UserData',ud);

Matt J

Matt J (view profile)


There seems to be a duplicate of this submission at

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?

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
    hFig = get(hAxes,'Parent');
    set(hAxes, 'UserData',[]);


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


Nispio (view profile)



Simon (view profile)



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


Revised to work with R2014b and still be backward compatible.

MATLAB Release
MATLAB 8.1 (R2013a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video