[Matplotlib-devel] Setting the mathtext font via the object oriented API?

Nathan Goldbaum nathan12343 at gmail.com
Tue May 31 22:12:56 EDT 2016


I think I'm going to work around this by wrapping the places where we draw
matplotlib figures with context managers for the classic style, making use
of matplotlib.style.context. We only draw figures in a few places, so it's
a lot less invasive to use the context manager than I originally feared.
Specifying the style exactly should also make it easier for us to avoid
issues due to people's local matplotlib settings.

As far as I can see, the font used for mathtext rendering can only be
controlled by the mathtext.fontset rcparam (see the function
MathTextParser.parse). Since I liked the old default - computer modern - I
never noticed that it wasn't possible to control it via the object oriented
API.

I'm going to close the issue I linked to in the OP and instead open a
feature request issue asking for a way to control the font of mathtext
without messing with the rcparam system. Maybe it would also make sense for
the font chosen for mathtext to try to match the font given by the
FontProperties instance - for example, switching to a serif font if the
FontProperties for the Text instance correspond to a serif font.

On Tue, May 31, 2016 at 5:51 PM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:

> Hi all,
>
> This is in reference to an issue I opened today:
>
> https://github.com/matplotlib/matplotlib/issues/6514#issuecomment-222833315
>
> Is there a way to tell the mathtext renderer to use the computer modern
> font that used to be the default? I know I can do this via the
> mathtext.fontset rcparam, but this is in the context of a library that
> depends on matplotlib, so I'd prefer a way to do this without overriding
> any rcparams a user has set already.
>
> For non-mathtext text, this is easy, I just need to set the FontProperties
> instance associated with the Text object. However, there doesn't seem to be
> a way to do something similar for mathtext.
>
> Thanks for your help,
>
> Nathan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20160531/512fcec3/attachment.html>


More information about the Matplotlib-devel mailing list