using subscripts and tex in labels

hi all,

two quick questions about labels. first, is there a way to make
subscripts/superscripts *without* using TeX in labels? For example, I
use helvetica in all my labels and I want to plot something like:
plt.xlabel("log10") where "10" is a subscript of "log", but without
doing: plt.xlabel(r"$\log_{10}$"), since that will use LaTeX fonts
instead of my helvetica font.

second question, when using TeX, I tried the following TeX command in labels:
plt.annotate(r"\frac{\sigma}{\sqrt{\mu}}", ....) but it complains that
"not all arguments converted during string formatting" -- but it seems
like correct TeX to me. if I try r"\frac{1}{2}" then it works, but
using \sigma and \sqrt inside breaks it.. any idea how to fix this?

thanks.

hi all,

two quick questions about labels. first, is there a way to make

subscripts/superscripts without using TeX in labels? For example, I

use helvetica in all my labels and I want to plot something like:

plt.xlabel(“log10”) where “10” is a subscript of “log”, but without

doing: plt.xlabel(r"\log_{10}"), since that will use LaTeX fonts

instead of my helvetica font.

Unicode strings might be the answer for this. Though needs someone’s confirmation.

second question, when using TeX, I tried the following TeX command in labels:

plt.annotate(r"\frac{\sigma}{\sqrt{\mu}}", …) but it complains that

“not all arguments converted during string formatting” – but it seems

like correct TeX to me. if I try r"\frac{1}{2}" then it works, but

using \sigma and \sqrt inside breaks it… any idea how to fix this?

Have you forgotten “$” ? The following works correctly in my system.

plt.xlabel(r"\frac{\sigma}{\sqrt{\mu}}")

···

On Sun, Jan 31, 2010 at 4:21 PM, per freem <perfreem@…83…287…> wrote:

thanks.


The Planet: dedicated and managed hosting, cloud storage, colocation

Stay online with enterprise data centers and the best network in the business

Choose flexible plans and management services without long-term contracts

Personal 24x7 support from experience hosting pros just a phone call away.

http://p.sf.net/sfu/theplanet-com


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan

per freem wrote:

hi all,

two quick questions about labels. first, is there a way to make
subscripts/superscripts *without* using TeX in labels? For example, I
use helvetica in all my labels and I want to plot something like:
plt.xlabel("log10") where "10" is a subscript of "log", but without
doing: plt.xlabel(r"\\log\_\{10\}"), since that will use LaTeX fonts
instead of my helvetica font.

See the mathtext options in matplotlibrc.template. It looks like what you need is

matplotlib.rc('mathtext', fontset='stixsans')

maybe with the additional kwarg, default='regular', if you don't want italics.

All this is with text.usetex=False (the default).

second question, when using TeX, I tried the following TeX command in labels:
plt.annotate(r"\frac{\sigma}{\sqrt{\mu}}", ....) but it complains that
"not all arguments converted during string formatting" -- but it seems
like correct TeX to me. if I try r"\frac{1}{2}" then it works, but
using \sigma and \sqrt inside breaks it.. any idea how to fix this?

This is working for me with usetex=False or True but including dollar signs to signal the use of mathtext (or TeX) parsing.

Eric