Plot Settings#

class PlotSettings(theme: theme | None = None, override: bool = False, file_format: str = 'png', width: int = 10, height: int = 8, dpi: int = 300, transparent: bool = False, primary_color: str | None = None, secondary_color: str | None = None, accent_color: str | None = None)[source]#

Bases: object

Control the styling and file I/O settings for plots.

This class provides a centralized way to control all aspects of plot generation and styling in the Brisk package. It manages both file I/O settings (file_format, size, DPI, etc.) and plot styling using plotnine theme objects.

The plot styling settings apply to built-in plots automatically and to custom plotnine plots via the get_theme() method. File I/O settings are used by the IOService when saving plots.

Attributes:
VALID_FORMATSset

Set of valid file formats for plot output

file_io_settingsDict[str, Any]

Dictionary containing file I/O settings (file_format, width, height, dpi, transparent)

primary_colorstr

Primary color for plots (default: “#1175D5”)

secondary_colorstr

Secondary color for plots (default: “#00A878”)

accent_colorstr

Accent color for plots (default: “#DE6B48”)

themepn.theme

The plotnine theme object for plot styling

Notes

The class supports theme inheritance where custom themes can either override the default brisk theme completely or extend it by combining with the default theme.

Examples

>>> from brisk.theme.plot_settings import PlotSettings
>>> import plotnine as pn
>>> 
>>> # Basic settings
>>> plot_settings = PlotSettings(file_format="svg", width=12, height=8)
>>> 
>>> # Custom theme with override
>>> custom_theme = pn.theme_minimal()
>>> plot_settings = PlotSettings(theme=custom_theme, override=True)
>>> 
>>> # Custom colors
>>> plot_settings = PlotSettings(
...     primary_color="#FF6B6B",
...     secondary_color="#4ECDC4",
...     accent_color="#45B7D1"
... )
VALID_FORMATS = {'jpeg', 'jpg', 'pdf', 'png', 'svg'}#
export_params() Dict[str, Any][source]#

Export PlotSettings to a JSON-serializable dictionary.

This method exports all PlotSettings parameters to a dictionary that can be serialized to JSON. The theme object is serialized using a custom serializer to make it JSON-compatible.

Returns:
Dict[str, Any]

Dictionary containing all PlotSettings parameters: - file_io_settings: File I/O settings dictionary - colors: Color settings dictionary - theme_json: Serialized theme object as JSON-compatible string

Notes

The theme object is serialized using ThemePickleJSONSerializer to convert the plotnine theme object into a JSON-compatible file_format that can be reconstructed later.

Examples

>>> plot_settings = PlotSettings(file_format="svg", width=12, height=8)
>>> params = plot_settings.export_params()
>>> # Save to JSON file
>>> import json
>>> with open("plot_settings.json", "w") as f:
...     json.dump(params, f)
get_colors() Dict[str, str][source]#

Get the current color settings as a dictionary.

This method returns a dictionary containing all the current color settings for the plot theme.

Returns:
Dict[str, str]

A dictionary containing: - primary_color: Primary color for plots (str) - secondary_color: Secondary color for plots (str) - accent_color: Accent color for plots (str)

Examples

>>> plot_settings = PlotSettings(
...     primary_color="#FF6B6B",
...     secondary_color="#4ECDC4",
...     accent_color="#45B7D1"
... )
>>> colors = plot_settings.get_colors()
>>> print(colors["primary_color"])  # "#FF6B6B"
get_io_settings() Dict[str, Any][source]#

Get the current file I/O settings.

This method returns a copy of the current file I/O settings dictionary containing file_format, width, height, DPI, and transparency settings.

Returns:
Dict[str, Any]

A copy of the file I/O settings dictionary containing: - file_format: File file_format (str) - width: Figure width in inches (int) - height: Figure height in inches (int) - dpi: Resolution in dots per inch (int) - transparent: Whether to use transparent background (bool)

Examples

>>> plot_settings = PlotSettings(file_format="svg", width=12, height=8)
>>> io_settings = plot_settings.get_io_settings()
>>> print(io_settings["file_format"])  # "svg"
>>> print(io_settings["width"])   # 12
get_theme() theme[source]#

Get the current theme object.

This method returns the current plotnine theme object that is being used for plot styling.

Returns:
pn.theme

The current plotnine theme object

Examples

>>> plot_settings = PlotSettings()
>>> theme = plot_settings.get_theme()
>>> # Use theme with plotnine plots
>>> p = pn.ggplot(data) + pn.geom_point() + theme