Skip to content

Keep Matplotlib's global rcParams when a canvas is drawn - #83

Merged
max-models merged 1 commit into
develfrom
keep-global-rcparams
Nov 6, 2026
Merged

max-models merged 1 commit into
develfrom
keep-global-rcparams

Conversation

@max-models

@max-models max-models commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Drawing a canvas with Matplotlib changed the global rcParams for good: setup_tex_fonts and setup_plotstyle write serif fonts, inward ticks, dotted grids and the canvas font size into plt.rcParams. Every figure drawn afterwards in the same process got that style, including figures of other packages. plasma-plots' docs, for example, had serif fonts on every figure drawn after a scope-profiler chart.

What changes

  • plot_matplotlib draws inside plt.rc_context(), so the global rcParams are the same afterwards. The canvas figure still gets its style, because fonts, ticks and grids are fixed when the artists are created.
  • It records which rcParams the style changed. savefig and show apply them again while saving and showing, so LaTeX text, which reads the font family when it is drawn, still renders with the canvas fonts.
  • The Plotly path called setup_tex_fonts only for its side effect on Matplotlib. It now runs inside rc_context too.
  • The TikZ path already restored the style and is unchanged.

Tests

  • New tests check that the global style is unchanged after drawing, saving and the Plotly path, that the canvas figure still has the serif fonts and inward ticks, and that saving draws with the canvas fonts.
  • The main test fails without the change.
  • All 327 tests pass locally; 3 skip without pdflatex.

@max-models
max-models merged commit d4490e5 into devel Nov 6, 2026
47 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant