|
From: per f. <per...@gm...> - 2009-03-04 00:54:37
|
hi all,
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')
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?
i want all the tick labels and text to be in the default font. for example,
in xlabel('\Delta direction'), it should have the sans-serif font in
"direction" but use tex for the \Delta.
is there a way to do this?
thank you.
|
|
From: Jouni K. S. <jk...@ik...> - 2009-03-04 07:00:16
|
per freem <per...@gm...> 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
|
|
From: Jeffrey F. <mat...@je...> - 2009-03-04 14:53:39
|
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 <jk...@ik...> wrote:
> per freem <per...@gm...> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
|