x, y labels with varying font styles

Hey, All,

I’ve combed the documentation ad nauseum, but I can’t find a solution for this one, besides a very brute-force one.

Let’s say I’ve set my default sans-serif font as ‘Arial’. Fine.

Now, let’s say, in a standard plot, I set the x label of this plot using something like:

matplotlib.pyplot.xlabel(‘f(x) (widgets/quatloo)’)

Fine again.

But now, let’s say I want to italicize only the ‘f’ and ‘x’. I can’t find any easy way to do that while retaining the Arial font.

And no, I don’t want to use TeX. Target users’ computers might not have it.

I’ve tried using mathtext, but that uses one of mathtext’s fonts, not mine
(computer modern, etc., or sansserif, etc.)

I’ve tried setting mathregular, but that won’t allow me to vary italic/nonitalic text.

I’m left with not labeling the axes at all, but simply putting four different text objects next to each other and hoping that it doesn’t look too jury-rigged.

Either that, or Photoshop the puppy.

Any suggestions?

Chad

But now, let’s say I want to italicize only the ‘f’ and ‘x’. I can’t find any easy way to do that while retaining the Arial font.

And no, I don’t want to use TeX. Target users’ computers might not have it.

That’s fine, that’s why matplotlib imitates TeX with mathtext…

I’ve tried using mathtext, but that uses one of mathtext’s fonts, not mine
(computer modern, etc., or sansserif, etc.)

I am sure there must be some way to change the font, but Arial might not be supported for this… haven’t tried though.

I’ve tried setting mathregular, but that won’t allow me to vary italic/nonitalic text.

Could you include some examples of what you tried?

I’m left with not labeling the axes at all, but simply putting four different text objects next to each other and hoping that it doesn’t look too jury-rigged.

Yeah, based on your requirements (italicize individual characters) your choices are to either use the latex-like syntax that matplotlib allows for, or to individually set the characters in their own text boxes. But, really, I think if you rethink your requirements, then you will realize that mathtext is the better way to go. It looks much more aesthetically pleasing that way.

Either that, or Photoshop the puppy.

Let’s see if we can avoid that…

Cheers,
Ben Root

···

On Wed, Sep 14, 2011 at 4:34 PM, CAB <cabraut@…9…> wrote:

Mathtext only works with particular math fonts – in order to do
math layout, extra metrics are required to be in the font that
aren’t in most standard fonts such as Arial.

    We need some sort of rich text support in matplotlib (such as

HTML-like or something), but it doesn’t currently exist.

    Mike
···

On 09/14/2011 05:48 PM, Benjamin Root wrote:

On Wed, Sep 14, 2011 at 4:34 PM, CAB <cabraut@…9…> > wrote:

            But now, let's say I want to italicize only the 'f'

and ‘x’. I can’t find any easy way to do that while
retaining the Arial font.

            And no, I don't want to use TeX.  Target users'

computers might not have it.

      That's fine, that's why matplotlib imitates TeX with

mathtext…

            I've tried using mathtext, but that uses one of

mathtext’s fonts, not mine (computer modern, etc., or
sansserif, etc.)

      I am sure there must be some way to change the font, but Arial

might not be supported for this… haven’t tried though.