TeX $\times$ symbol not working in matplotlib?
gwhite
gwhite at ti.com
Fri Apr 18 12:48:39 EDT 2014
On Friday, April 18, 2014 9:24:55 AM UTC-7, Chris "Kwpolska" Warrick wrote:
> On Fri, Apr 18, 2014 at 6:18 PM, gwhite <gwhite at ti.com> wrote:
>
> > I am trying to understand how to get the TeX "\times" symbol to work. It is in the title() string in the code I pasted in. The "\circ" symbol seems fine, by comparison. "\times" ends up as "imes" in the figure title.
> >
> > I am probably doing something dumb (hey, maybe a lot of dumb things!), but if you can spot and describe my mistake, I would be quite happy about that.
>
> > plt.title('$\mathrm{poles}$ $(\times)$ \
> > $\mathrm{\&}$ $\mathrm{zeros}$ \
> > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
> > fontsize=16)
>
> You're using a regular string. In which backspaces can be used in
> escapes. \t is one of those escapes, it is the tab character. In
> order to fix, add the letter "r" before the opening quote. Like this:
>
> > plt.title(r'$\mathrm{poles}$ $(\times)$ \
> > $\mathrm{\&}$ $\mathrm{zeros}$ \
> > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
> > fontsize=16)
>
> Moreover, in the next two things, you already did it right in the first place:
>
> > plt.xlabel(r'$\sigma$', fontsize=16)
> > plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16)
Thanks Chris! That worked.
I faked myself out since the $(\circ)$ worked *without* the little r prefix. I was blind to it. I guess the difference must be there is no \c thingy to override \circ, so it just does the circle.
Thanks for the note on how the r prefix works. I knew I would screw myself sooner or later on that.
Getting regular text mixed with math text, but with the same font (in regular or italic) is a bit clumsy, I suppose. (I mean getting the spaces in.) At least I can do it.
I did this too, and it also seems to work:
plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\
r'$\mathrm{\&}$', r'$\mathrm{zeros}$',
r'$(\circ)$', r'$\mathrm{of}$',\
r'$T(s)T(-s)$']), fontsize=16)
More information about the Python-list
mailing list