using tex in labels but retaining sans-serif font

per freem <perfreem@...287...> writes:

i am using the tex feature to put some greek symbols in some labels of my
plots. for example,

rcParams['text.usetex'] = True
plot(a, b, 'o')
xlabel('\Delta direction')

Are you sure you need usetex? Matplotlib's own mathtext renderer is
really quite good these days, and expressions like

xlabel(r'\\Delta direction')

should work just fine without usetex.

the '\Delta' is rendered correctly but that changes the fonts of the
tick labels and of all the text in the labels to tex's default font
(which looks like times new roman). is there a way to use tex only for
greek symbols but retain the default sans-serif font of matplotlib for
all the other things?

No, usetex is an all-or-nothing choice. In principle it should be
possible to change matplotlib to send only some strings (or string
parts) to TeX, but I guess no-one has needed such a feature badly
enough - the built-in mathtext renderer is good enough for most uses,
and the remaining reason to use usetex is that you are including your
figure in a LaTeX document and want the fonts to perfectly match the
surrounding text, and in that case the current behavior is exactly
right.

The ordinary way to specify fonts works with the usetex engine, with the
restriction that only some fonts are usable with LaTeX. The following
dictionary (in texmanager.py) has the recognized fonts as keys and the
corresponding LaTeX packages as (the second part of) the values:

    font_info = {'new century schoolbook': ('pnc',
                                            r'\renewcommand{\rmdefault}{pnc}'),
                'bookman': ('pbk', r'\renewcommand{\rmdefault}{pbk}'),
                'times': ('ptm', r'\usepackage{mathptmx}'),
                'palatino': ('ppl', r'\usepackage{mathpazo}'),
                'zapf chancery': ('pzc', r'\usepackage{chancery}'),
                'cursive': ('pzc', r'\usepackage{chancery}'),
                'charter': ('pch', r'\usepackage{charter}'),
                'serif': ('cmr', ''),
                'sans-serif': ('cmss', ''),
                'helvetica': ('phv', r'\usepackage{helvet}'),
                'avant garde': ('pag', r'\usepackage{avant}'),
                'courier': ('pcr', r'\usepackage{courier}'),
                'monospace': ('cmtt', ''),
                'computer modern roman': ('cmr', ''),
                'computer modern sans serif': ('cmss', ''),
                'computer modern typewriter': ('cmtt', '')}

···

--
Jouni K. Sepp�nen

I’ve found that putting the text you want to be sans-serif inside \sf{} works. So something like:

xlabel(r’$\sf{\Delta direction})

-Jeffrey

···

On Wed, Mar 4, 2009 at 1:59 AM, Jouni K. Seppänen <jks@…397…> wrote:

per freem <perfreem@…287…> writes:

i am using the tex feature to put some greek symbols in some labels of my

plots. for example,

rcParams[‘text.usetex’] = True

plot(a, b, ‘o’)

xlabel(‘\Delta direction’)

Are you sure you need usetex? Matplotlib’s own mathtext renderer is

really quite good these days, and expressions like

xlabel(r’\Delta direction’)

should work just fine without usetex.

the ‘\Delta’ is rendered correctly but that changes the fonts of the

tick labels and of all the text in the labels to tex’s default font

(which looks like times new roman). is there a way to use tex only for

greek symbols but retain the default sans-serif font of matplotlib for

all the other things?

No, usetex is an all-or-nothing choice. In principle it should be

possible to change matplotlib to send only some strings (or string

parts) to TeX, but I guess no-one has needed such a feature badly

enough - the built-in mathtext renderer is good enough for most uses,

and the remaining reason to use usetex is that you are including your

figure in a LaTeX document and want the fonts to perfectly match the

surrounding text, and in that case the current behavior is exactly

right.

The ordinary way to specify fonts works with the usetex engine, with the

restriction that only some fonts are usable with LaTeX. The following

dictionary (in texmanager.py) has the recognized fonts as keys and the

corresponding LaTeX packages as (the second part of) the values:

font_info = {'new century schoolbook': ('pnc',

                                        r'\renewcommand{\rmdefault}{pnc}'),

            'bookman': ('pbk', r'\renewcommand{\rmdefault}{pbk}'),

            'times': ('ptm', r'\usepackage{mathptmx}'),

            'palatino': ('ppl', r'\usepackage{mathpazo}'),

            'zapf chancery': ('pzc', r'\usepackage{chancery}'),

            'cursive': ('pzc', r'\usepackage{chancery}'),

            'charter': ('pch', r'\usepackage{charter}'),

            'serif': ('cmr', ''),

            'sans-serif': ('cmss', ''),

            'helvetica': ('phv', r'\usepackage{helvet}'),

            'avant garde': ('pag', r'\usepackage{avant}'),

            'courier': ('pcr', r'\usepackage{courier}'),

            'monospace': ('cmtt', ''),

            'computer modern roman': ('cmr', ''),

            'computer modern sans serif': ('cmss', ''),

            'computer modern typewriter': ('cmtt', '')}

Jouni K. Seppänen

http://www.iki.fi/jks


Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA

-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise

-Strategies to boost innovation and cut costs with open source participation

-Receive a $600 discount off the registration fee with the source code: SFAD

http://p.sf.net/sfu/XcvMzF8H


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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