Skip to content

Scope plt.style.use and sns.set_palette so they're not global #4

@DevanshSrajput

Description

@DevanshSrajput

Context
Agent.py:942-943 mutates matplotlib's and seaborn's global
rcParams from inside create_visualizations. That means every
other matplotlib consumer in the same Python process inherits
the "default + husl" look — and re-instantiating the agent
silently reverts the user's style. The fix is to scope the
mutation to the chart-rendering block.

What to change
In Agent.py:create_visualizations, wrap the _save calls (or
the per-chart plt.subplots / plt.figure blocks) with
plt.style.context(...). The two-line setup at lines 942-943
becomes a single with plt.style.context('default'): sns.set_palette("husl")
block scoped to the rendering loop, or you can drop the
set_palette entirely if the default husl is acceptable.

How to verify

  • Import matplotlib in a separate script, change the user's
    rcParams to a custom style, then call
    agent.create_visualizations(df, "f.csv"). After the call,
    the custom rcParams must still be in effect.
  • python -m unittest discover -s tests -v is green; specifically
    the CreateVisualizationsGuardTests continue to produce the
    expected chart types.

Skill: matplotlib, scoping.
Estimated effort: S.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions