Making mathtex output look nicer

Hello,

Not that I like asking the same question again and again, but I just couldn’t find a way to fix one annoyance on my figures when I use mathtex formatted labels. Here is one example figure: http://img14.imageshack.us/img14/4443/mathtex.png

Set the label

host.set_ylabel(r"DMT CCN Concentration [#/$cm^3$]")

On the y-label, I always get an extra space after the formatted text even if I don’t explicitly put myself. What is the known cure for this issue? This figure and similars will go onto my poster, and thesis and further on a paper. I would really like to know if there a way to fix this by making some changes on my code or matplotlibrc file.

Thanks.

Here is the relevant sections of my rc file:

FONT

···

font properties used by text.Text. See

http://matplotlib.sourceforge.net/matplotlib.font_manager.html for more

information on font properties. The 6 font properties used for font

matching are given below with their default values.

The font.family property has five values: ‘serif’ (e.g. Times),

‘sans-serif’ (e.g. Helvetica), ‘cursive’ (e.g. Zapf-Chancery),

‘fantasy’ (e.g. Western), and ‘monospace’ (e.g. Courier). Each of

these font families has a default list of font names in decreasing

order of priority associated with them.

The font.style property has three values: normal (or roman), italic

or oblique. The oblique style will be used for italic, if it is not

present.

The font.variant property has two values: normal or small-caps. For

TrueType fonts, which are scalable fonts, small-caps is equivalent

to using a font size of ‘smaller’, or about 83% of the current font

size.

The font.weight property has effectively 13 values: normal, bold,

bolder, lighter, 100, 200, 300, …, 900. Normal is the same as

400, and bold is 700. bolder and lighter are relative values with

respect to the current weight.

The font.stretch property has 11 values: ultra-condensed,

extra-condensed, condensed, semi-condensed, normal, semi-expanded,

expanded, extra-expanded, ultra-expanded, wider, and narrower. This

property is not currently implemented.

The font.size property is the default font size for text, given in pts.

12pt is the standard value.

#font.family : sans-serif
#font.style : normal
#font.variant : normal
#font.weight : medium
#font.stretch : normal

note that font.size controls default text sizes. To configure

special text sizes tick labels, axes, labels, title, etc, see the rc

settings for axes and ticks. Special text sizes can be defined

relative to font.size, using the following values: xx-small, x-small,

small, medium, large, x-large, xx-large, larger, or smaller

#font.size : 12.0
#font.serif : Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
#font.sans-serif : Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
#font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive
#font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy
#font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace

TEXT

text properties used by text.Text. See

http://matplotlib.sourceforge.net/matplotlib.text.html for more

information on text properties

#text.color : black

LaTeX customizations. See http://www.scipy.org/Wiki/Cookbook/Matplotlib/UsingTex

text.usetex : False # use latex for all text handling. The following fonts
# are supported through the usual rc parameter settings:
# new century schoolbook, bookman, times, palatino,
# zapf chancery, charter, serif, sans-serif, helvetica,
# avant garde, courier, monospace, computer modern roman,
# computer modern sans serif, computer modern typewriter
# If another font is desired which can loaded using the
# LaTeX \usepackage command, please inquire at the
# matplotlib mailing list
#text.latex.unicode : False # use “ucs” and “inputenc” LaTeX packages for handling
# unicode strings.
#text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
# AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
# IF THIS FEATURE DOES NOT DO WHAT YOU EXPECT IT TO.
# preamble is a comma separated list of LaTeX statements
# that are included in the LaTeX document preamble.
# An example:
# text.latex.preamble : \usepackage{bm},\usepackage{euler}
# The following packages are always loaded with usetex, so
# beware of package collisions: color, geometry, graphicx,
# type1cm, textcomp. Adobe Postscript (PSSNFS) font packages
# may also be loaded, depending on your font settings

#text.dvipnghack : None # some versions of dvipng don’t handle alpha
# channel properly. Use True to correct
# and flush ~/.matplotlib/tex.cache
# before testing and False to force
# correction off. None will try and
# guess based on your dvipng version

#text.markup : ‘plain’ # Affects how text, such as titles and labels, are
# interpreted by default.
# ‘plain’: As plain, unformatted text
# ‘tex’: As TeX-like text. Text between $'s will be
# formatted as a TeX math expression.
# This setting has no effect when text.usetex is True.
# In that case, all text will be sent to TeX for
# processing.

The following settings allow you to select the fonts in math mode.

They map from a TeX font name to a fontconfig font pattern.

These settings are only used if mathtext.fontset is ‘custom’.

Note that this “custom” mode is unsupported and may go away in the

future.

mathtext.default : regular
#mathtext.cal : cursive
#mathtext.rm : serif
#mathtext.tt : monospace
#mathtext.it : serif:italic
#mathtext.bf : serif:bold
#mathtext.sf : sans
#mathtext.fontset : cm # Should be ‘cm’ (Computer Modern), ‘stix’,
# ‘stixsans’ or ‘custom’
#mathtext.fallback_to_cm : True # When True, use symbols from the Computer Modern
# fonts when a symbol can not be found in one of
# the custom math fonts.


Gökhan

It’s a bug without an easy solution. Realistically, we probably need
to make two passes with the mathtext parser to determine spacing.

A workaround is to use the \hspace command:

r"[#/$cm^3\hspace{-0.3}$]"

Mike

···

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


Matplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks Mike, that did the trick.

I was giving a space before units to make them look equal. Yours is much neater.

Has this bug submitted on SF. I can go ahead a file one if not.

···

On Fri, Oct 23, 2009 at 9:57 AM, Michael Droettboom <mdroe@…86…> wrote:

It’s a bug without an easy solution. Realistically, we probably need
to make two passes with the mathtext parser to determine spacing.

A workaround is to use the \hspace command:

r"[#/$cm^3\hspace{-0.3}$]"

Mike

On 10/23/2009 09:44 AM, Gökhan Sever wrote:

Hello,

Not that I like asking the same question again and again, but I just
couldn’t find a way to fix one annoyance on my figures when I use
mathtex formatted labels. Here is one example figure: http://img14.imageshack.us/img14/4443/mathtex.png

Set the label

host.set_ylabel(r"DMT CCN Concentration [#/$cm^3$]")

On the y-label, I always get an extra space after the formatted text
even if I don’t explicitly put myself. What is the known cure for this
issue? This figure and similars will go onto my poster, and thesis and
further on a paper. I would really like to know if there a way to fix
this by making some changes on my code or matplotlibrc file.

Thanks.

Here is the relevant sections of my rc file:

FONT

font properties used by text.Text. See

http://matplotlib.sourceforge.net/matplotlib.font_manager.html

for more

information on font properties. The 6 font properties used for font

matching are given below with their default values.

The font.family property has five values: ‘serif’ (e.g. Times),

‘sans-serif’ (e.g. Helvetica), ‘cursive’ (e.g. Zapf-Chancery),

‘fantasy’ (e.g. Western), and ‘monospace’ (e.g. Courier). Each of

these font families has a default list of font names in decreasing

order of priority associated with them.

The font.style property has three values: normal (or roman), italic

or oblique. The oblique style will be used for italic, if it is not

present.

The font.variant property has two values: normal or small-caps. For

TrueType fonts, which are scalable fonts, small-caps is equivalent

to using a font size of ‘smaller’, or about 83% of the current font

size.

The font.weight property has effectively 13 values: normal, bold,

bolder, lighter, 100, 200, 300, …, 900. Normal is the same as

400, and bold is 700. bolder and lighter are relative values with

respect to the current weight.

The font.stretch property has 11 values: ultra-condensed,

extra-condensed, condensed, semi-condensed, normal, semi-expanded,

expanded, extra-expanded, ultra-expanded, wider, and narrower. This

property is not currently implemented.

The font.size property is the default font size for text, given in

pts.

12pt is the standard value.

#font.family : sans-serif

#font.style : normal

#font.variant : normal

#font.weight : medium

#font.stretch : normal

note that font.size controls default text sizes. To configure

special text sizes tick labels, axes, labels, title, etc, see the rc

settings for axes and ticks. Special text sizes can be defined

relative to font.size, using the following values: xx-small, x-small,

small, medium, large, x-large, xx-large, larger, or smaller

#font.size : 12.0

#font.serif : Bitstream Vera Serif, New Century Schoolbook,
Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L,
Times New Roman, Times, Palatino, Charter, serif

#font.sans-serif : Bitstream Vera Sans, Lucida Grande, Verdana,
Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

#font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand,
cursive

#font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact,
Western, fantasy

#font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus
Mono L, Courier New, Courier, Fixed, Terminal, monospace

TEXT

text properties used by text.Text. See

http://matplotlib.sourceforge.net/matplotlib.text.html

for more

information on text properties

#text.color : black

LaTeX customizations. See http://www.scipy.org/Wiki/Cookbook/Matplotlib/UsingTex

text.usetex : False # use latex for all text handling. The
following fonts

                          # are supported through the usual rc

parameter settings:

                          # new century schoolbook, bookman, times,

palatino,

                          # zapf chancery, charter, serif,

sans-serif, helvetica,

                          # avant garde, courier, monospace,

computer modern roman,

                          # computer modern sans serif, computer

modern typewriter

                          # If another font is desired which can

loaded using the

                          # LaTeX \usepackage command, please

inquire at the

                          # matplotlib mailing list

#text.latex.unicode : False # use “ucs” and “inputenc” LaTeX packages
for handling

                        # unicode strings.

#text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO
LATEX FAILURES

                        # AND IS THEREFORE UNSUPPORTED. PLEASE DO

NOT ASK FOR HELP

                        # IF THIS FEATURE DOES NOT DO WHAT YOU

EXPECT IT TO.

                        # preamble is a comma separated list of

LaTeX statements

                        # that are included in the LaTeX document

preamble.

                        # An example:

                        # text.latex.preamble :

\usepackage{bm},\usepackage{euler}

                        # The following packages are always loaded

with usetex, so

                        # beware of package collisions: color,

geometry, graphicx,

                        # type1cm, textcomp. Adobe Postscript

(PSSNFS) font packages

                        # may also be loaded, depending on your

font settings

#text.dvipnghack : None # some versions of dvipng don’t handle
alpha

                         # channel properly.  Use True to correct

                         # and flush ~/.matplotlib/tex.cache

                         # before testing and False to force

                         # correction off.  None will try and

                         # guess based on your dvipng version

#text.markup : ‘plain’ # Affects how text, such as titles and
labels, are

                            # interpreted by default.

                            # 'plain': As plain, unformatted text

            # 'tex': As TeX-like text.  Text between $'s will be

            # formatted as a TeX math expression.

            # This setting has no effect when text.usetex is True.

            # In that case, all text will be sent to TeX for

            # processing.

The following settings allow you to select the fonts in math mode.

They map from a TeX font name to a fontconfig font pattern.

These settings are only used if mathtext.fontset is ‘custom’.

Note that this “custom” mode is unsupported and may go away in the

future.

mathtext.default : regular

#mathtext.cal : cursive

#mathtext.rm : serif

#mathtext.tt :
monospace

#mathtext.it :
serif:italic

#mathtext.bf :
serif:bold

#mathtext.sf : sans

#mathtext.fontset : cm # Should be ‘cm’ (Computer Modern), ‘stix’,

                   # 'stixsans' or 'custom'

#mathtext.fallback_to_cm : True # When True, use symbols from the
Computer Modern

                 # fonts when a symbol can not be found in one of

             # the custom math fonts.

Gökhan



Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference



Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Come build with us! The BlackBerry® Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and stay

ahead of the curve. Join us from November 9 - 12, 2009. Register now!

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


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


Gökhan