Search code examples
matlabannotationsgraphing

matlab: putting a circled number onto a graph


I want to put a circled number on a graph as a marker near (but not on) a point. Sounds easy, but I also want to be invariant of zoom/aspect ratio changes.

Because of this invariant, I can't draw a circle as a line object (without redrawing it upon rescale); if I use a circle marker, I'd have to adjust its offset upon rescale.

The simplest approach I can think of is to use the Unicode or Wingdings characters ① ② ③ etc. in a string for the text() function. But unicode doesn't seem to work right, and the following sample only works with ① and not for the other numbers (which yield rectangle boxes):

works:

clf; text(0.5,0.5,char(129),'FontName','WingDings')

doesn't work (should be a circled 2):

clf; text(0.5,0.5,char(130),'FontName','WingDings')

What gives, and can anyone suggest a workaround?


Solution

  • This seems to work for me, uses Matlab's latex interpreter, and \textcircled:

    clf; text(0.5, 0.5, '$\textcircled{2}$', 'Interpreter', 'latex')
    

    The \textcircled command seems have some offset problems, maybe you can try to improve the used latex command and let us know :)

    Following the above link, for example, I get better results with:

    clf; text(0.5, 0.5, '$\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {2}}}$', 'Interpreter', 'latex')
    

    Still, two digit numbers look awful.