Use theme font also for LaTeX

Open
#942 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
matplotlib, python

Research direction

Start with the reproducible plotnine example and inspect how theme text fonts are applied alongside matplotlib's LaTeX and mathtext settings. Trace the theme font handling and determine the relevant matplotlib configuration; done means labels rendered in LaTeX use the font family specified by the theme without requiring separate global rcParams.

Written by the indexing model from the issue text.

Description

Apparently, matplotlib uses different rcParams for controlling the font used in LaTeX environments vs outside (see https://stackoverflow.com/a/27697390). This causes behaviour which is IMO inconsistent, where the font family specified in the theme is not used within LaTeX environments.

Reproducible example to show what I mean:

from plotnine import ggplot, geom_point, aes, theme, labs, element_text
from plotnine.data import penguins

(ggplot(penguins, aes(x="bill_length_mm", y="bill_depth_mm")) 
 + labs(x="l_bill", y=r"$d_\text{bill}$")
 + theme(text = element_text(family="Noto Serif"), figure_size=(3,2))
 + geom_point()
)

yields this:

Image

where the LaTeX in the y axis label does not use the serif font which I specified in the theme

Prepending this:

import matplotlib
matplotlib.rcParams['mathtext.fontset'] = 'custom'
matplotlib.rcParams['mathtext.rm'] = 'Noto Serif'
matplotlib.rcParams['mathtext.it'] = 'Noto Serif:italic'

achieves the desired result in this case, but of course, the theme information is no longer stored in the theme.

Is it possible to change the behaviour such that the LaTeX font follows the theme font?

Dominant language
Python
Stars
4.8k
Forks
269
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from has2k1/plotnine

All issues in has2k1/plotnine

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.