# Font weight on axes/labels

I'm trying to adjust the font weight on some of my plots - I'd like to
have the numbers along the axis ticks be bold instead of regular font
like the default setting. The problem is, nothing I do seems to
change the font weight. I've changed everything I can font in
matplotlibrc to bold, and when I go in and explicitly look at the
XTick or YTick objects and their text properties, it even claims the
text is bold... yet the text is normal weight font when displayed on
the plot.

A would also like to have the plot labels be bolder, as well, and I
can't seem to change that either.

Note that I have usetex as True, and I realize that this means the
labels, at least, are rendered through TeX... but I'm not clear on how
I can change the font properties to render bold versions of all the
TeX fonts I'm using (assuming this is possible). And I've been under
the impression that the default number formattes, at least, don't
render through TeX. So does anyone know how I can make all/any of my
text elemens bold?

I'm trying to adjust the font weight on some of my plots - I'd like to
have the numbers along the axis ticks be bold instead of regular font
like the default setting. The problem is, nothing I do seems to
change the font weight. I've changed everything I can font in
matplotlibrc to bold, and when I go in and explicitly look at the
XTick or YTick objects and their text properties, it even claims the
text is bold... yet the text is normal weight font when displayed on
the plot.

A would also like to have the plot labels be bolder, as well, and I
can't seem to change that either.

Note that I have usetex as True, and I realize that this means the
labels, at least, are rendered through TeX... but I'm not clear on how
I can change the font properties to render bold versions of all the
TeX fonts I'm using (assuming this is possible).

There is currently no support for bold ticklabels with usetex.

And I've been under
the impression that the default number formattes, at least, don't
render through TeX.

I don't understand, what default number formats? When you enable usetex, tex
is used to render all text.

So does anyone know how I can make all/any of my
text elemens bold?

The tex option was not designed to provide all the flexibility of matplotlib's
text handling. It was pretty hairy trying to support as many font properties
as we currently support.

Darren

···

On Sunday 22 June 2008 21:49:03 Erik Tollerud wrote:

Hmm... ok, so it is possible to pass some of the text in a plot
through TeX, but not all of the text? That's what the text.markup rc
parameter seems to be about, but I get an error saying that its an
unrecognized key if I use it...

I could have sworn I saw a post way back where someone managed to get
the tick numbers to be bold when usetex was on, but I've forgotten how
it was done and can't find the post now. Anyway, it's possible that
I'd turned usetex off as a test and not been paying close attention to
turning it back on...

Thanks for the quick response.

···

On Mon, Jun 23, 2008 at 5:21 AM, Darren Dale <dsdale24@...287...> wrote:

On Sunday 22 June 2008 21:49:03 Erik Tollerud wrote:

I'm trying to adjust the font weight on some of my plots - I'd like to
have the numbers along the axis ticks be bold instead of regular font
like the default setting. The problem is, nothing I do seems to
change the font weight. I've changed everything I can font in
matplotlibrc to bold, and when I go in and explicitly look at the
XTick or YTick objects and their text properties, it even claims the
text is bold... yet the text is normal weight font when displayed on
the plot.

A would also like to have the plot labels be bolder, as well, and I
can't seem to change that either.

Note that I have usetex as True, and I realize that this means the
labels, at least, are rendered through TeX... but I'm not clear on how
I can change the font properties to render bold versions of all the
TeX fonts I'm using (assuming this is possible).

There is currently no support for bold ticklabels with usetex.

And I've been under
the impression that the default number formattes, at least, don't
render through TeX.

I don't understand, what default number formats? When you enable usetex, tex
is used to render all text.

So does anyone know how I can make all/any of my
text elemens bold?

The tex option was not designed to provide all the flexibility of matplotlib's
text handling. It was pretty hairy trying to support as many font properties
as we currently support.

Darren

Hmm... ok, so it is possible to pass some of the text in a plot
through TeX, but not all of the text? That's what the text.markup rc
parameter seems to be about, but I get an error saying that its an
unrecognized key if I use it...

No, it's all or none. But with usetex=False you can use mathtext to
format your labels, and then only the stuff in $$will get formatted as math using the matplotlib fonts and math layout engine. I could have sworn I saw a post way back where someone managed to get the tick numbers to be bold when usetex was on, but I've forgotten how it was done and can't find the post now. Anyway, it's possible that I'd turned usetex off as a test and not been paying close attention to turning it back on... You should be able to do this with a custom formatter:: import matplotlib.ticker as ticker fmtbld = ticker.FormatStrFormatter(r'\textbf{%1.2f}') ax.xaxis.set_major_formatter(fmtbld) You should also be able to use textbf in the title, xlabel and ylabel. Of course, for this simple solution, you have to hard-code your precision. To take advantage of all the logic in ticker.ScalarFormatter, you could inherit from it and override some key pieces. But it might be better if we provide some hooks for you. Darren, in ScalarFormatter.set_format, we have code like:: if self._usetex: self.format = '%s' % self.format elif self._useMathText: self.format = '\mathdefault{%s}' % self.format We could consider exposing a font setting here. Something along the lines of self.fontcommand = None if self._usetex: if self.fontcommand = None: self.format = '%s' % self.format else: self.format = '%s{%s}' % (self.fontcommand, self.format) Then the user could do:: formatter = ticker.ScalarFormatter() formatter.fontcommand = r'\mathbf' and something similar for mathtext. JDH ··· On Mon, Jun 23, 2008 at 11:58 AM, Erik Tollerud <erik.tollerud@...287...> wrote: I'm not excited about adding user-accessible, usetex-specific properties and methods to classes outside of rcParams. It was a fair amount of work integrating as much customizability as we have now via rcParams, but we don't have the resources to support all the font properties in rcParams in usetex. I think it would be best to just use a custom formatter for this. ··· On Monday 23 June 2008 13:25:19 John Hunter wrote: On Mon, Jun 23, 2008 at 11:58 AM, Erik Tollerud <erik.tollerud@...287...> wrote: > Hmm... ok, so it is possible to pass some of the text in a plot > through TeX, but not all of the text? That's what the text.markup rc > parameter seems to be about, but I get an error saying that its an > unrecognized key if I use it... No, it's all or none. But with usetex=False you can use mathtext to format your labels, and then only the stuff in$$ will get formatted
as math using the matplotlib fonts and math layout engine.

> I could have sworn I saw a post way back where someone managed to get
> the tick numbers to be bold when usetex was on, but I've forgotten how
> it was done and can't find the post now. Anyway, it's possible that
> I'd turned usetex off as a test and not been paying close attention to
> turning it back on...

You should be able to do this with a custom formatter::

import matplotlib.ticker as ticker

fmtbld = ticker.FormatStrFormatter(r'$\textbf{%1.2f}$')
ax.xaxis.set_major_formatter(fmtbld)

You should also be able to use textbf in the title, xlabel and ylabel.

Of course, for this simple solution, you have to hard-code your
precision. To take advantage of all the logic in
ticker.ScalarFormatter, you could inherit from it and override some
key pieces. But it might be better if we provide some hooks for you.

Darren, in ScalarFormatter.set_format, we have code like::

if self._usetex:
self.format = '$%s$' % self.format
elif self._useMathText:
self.format = '$\mathdefault{%s}$' % self.format

We could consider exposing a font setting here. Something along the lines
of

self.fontcommand = None
if self._usetex:
if self.fontcommand = None:
self.format = '$%s$' % self.format
else:
self.format = '$%s{%s}$' % (self.fontcommand, self.format)

Then the user could do::

formatter = ticker.ScalarFormatter()
formatter.fontcommand = r'\mathbf'

and something similar for mathtext.