Skip to content

FIX: Isolate rcParams per savefig call (#69) - #129

Merged
Axect merged 1 commit into
devfrom
fix/plot-style-isolation
Nov 23, 2026
Merged

Axect merged 1 commit into
devfrom
fix/plot-style-isolation

Conversation

@Axect

@Axect Axect commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Fixes #69.

Plot2D::savefig runs its generated script in the embedded Python interpreter, which persists across calls. plt.style.use(...) and plt.rc(...) therefore mutate the global rcParams, and settings from one plot leak into the next. For example, saving with Default → IEEE → Nature in one program leaves IEEE's figure.dpi = 600 and font.serif = ["Times"] active for the Nature plot, which then fails with

! LaTeX Error: Command `\jmath' already defined.

This wraps the generated script in try: with plt.rc_context(): ... finally: plt.close(), so style/rc changes are restored after each call and the figure is always closed (it was never closed before).

Tested locally (matplotlib 3.11.2, scienceplots) by saving all four styles in one program in the orders Default → IEEE → Nature → Science (previously failed at Nature) and IEEE → Nature → Default → Science: all succeed, and the Default plot no longer inherits the previous style's figure size. cargo test --features plot passes.

@Axect
Axect merged commit dd02771 into dev Nov 23, 2026
16 checks passed
@Axect
Axect deleted the fix/plot-style-isolation branch November 23, 2026 02:47
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