Skip to content

Added plot style context managers to all plot methods#208

Open
Tom-Kingstone wants to merge 5 commits intodevelopfrom
Python_Toolkit-#204-PlotStyleContext
Open

Added plot style context managers to all plot methods#208
Tom-Kingstone wants to merge 5 commits intodevelopfrom
Python_Toolkit-#204-PlotStyleContext

Conversation

@Tom-Kingstone
Copy link
Contributor

NOTE: Depends on

Issues addressed by this PR

Closes #204

This removes the need to globally set plot style in dependent packages (see this PR for example), and allows setting it dynamically on method call using the kwarg "style_context". By default all the plot methods will use "python_toolkit.bhom" as the plot style, but this can be overridden by passing "default" to instead use whatever default matplotlib has currently set.

Moved the mplstyle files to the root of the package just to allow easy selection in code (allows passing "python_toolkit.bhom" instead of the path to the .mplstyle file)

Also added a dark theme (much to the benefit of my eyes on dark backgrounds) called bhom_dark.

This only works for matplotlib based plots, so plotly plots (like parallel_coordinate_plot) do not allow this.

Test files

Run the unit tests and ensure they pass, see it in action by using any of the matplotlib based plot methods (eg. heatmap) and passing style_context="python_toolkit.bhom" to the method.

Changelog

  • Added more flexible style selection through the style_context kwarg for all matplotlib plot methods
  • Added bhom_dark matplotlib style sheet.

Additional comments

packages that depend on python_toolkit must change any references to the python_toolkit/bhom/bhom.mplstyle file to python_toolkit/bhom.mplstyle or more cleanly with matplotlib, use "python_toolkit.bhom"

@Tom-Kingstone Tom-Kingstone self-assigned this Mar 12, 2026
@Tom-Kingstone Tom-Kingstone added the type:feature New capability or enhancement label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New capability or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change plot style functionality to be context based rather than global

1 participant