simplebench.reporters.graph.matplotlib packageπ
Matplotlib graph reporter module.
This module provides common base functionality for Matplotlib-based graph reporters.
The MatPlotLibOptions and MatPlotLibReporter classes
are not intended to be used directly, but rather to be subclassed by specific
reporters for line plots, bar charts, scatter plots, etc.
Public APIπ
MatPlotLibOptions: Options specific to Matplotlib based graph reporters.MatPlotLibReporter: Base class for Matplotlib based graph reporters.Style: Enumeration of available styles.Theme: Theme management for Matplotlib based graph reporters.SUPPORTED_IMAGE_TYPES: Frozen set of supported image output types.
- class simplebench.reporters.graph.matplotlib.MatPlotLibOptions(
- width: int | None = None,
- height: int | None = None,
- dpi: int | None = None,
- y_starts_at_zero: bool | None = None,
- x_labels_rotation: float | None = None,
- style: Style | None = None,
- theme: Theme | None = None,
- image_type: ImageType | None = None,
Bases:
GraphOptionsClass for holding MatPlotLib graph reporter specific options.
This class extends the
GraphOptionsinterface and forms a new interface for options specific to MatPlotLib-based graph reporters.It makes it easy to create graph reporters with MatPlotLib by providing a standard set of options that can be used across multiple reporters via subclassing.
It includes the defaults for various MatPlotLib reporter defaults that can be set globally for all MatPlotLib reporters via static methods, as well as instance-specific options that can be set when creating a
MatPlotLibOptionsinstance or when creating a benchmark test case.The philosophy behind having both static/global defaults and instance-specific options is to provide flexibility in configuration in a βsimple things should be simple, complex things should be possibleβ manner.
Users can set global defaults that apply to all MatPlotLib reporters, ensuring easy consistency across reports. At the same time, instance-specific options allow for customization on a per-report basis, enabling users to tailor the behavior of individual reports as needed.
The baseline defaults provided here are intended to offer a good balance between quality, appearance, and performance for most common use cases.
- Those defaults are as follows:
Width:
1500pixelsHeight:
750pixelsDPI:
150Y-axis starts at zero:
TrueX-axis labels rotation:
45.0degreesStyle:
DARK_BACKGROUNDTheme:
DefaultThemeImageType:
SVG
These defaults are used both by
Caseinstances when creating reports for specific test cases and byChoiceinstances when creating reports for all test cases under thatChoice.The semantics are that
optionstake precedence overoptionstake precedence over the class defaults. This allows for flexible configuration at multiple levels.
- Variables:
width (int) β The default width of the MatPlotLib output in pixels when rendered.
height (int) β The default height of the MatPlotLib output in pixels when rendered.
dpi (int) β The default DPI (dots per inch) for the MatPlotLib output when rendered.
y_starts_at_zero (bool) β The default for whether the Y-axis for graphs should start at zero.
x_labels_rotation (float) β The default rotation angle in degrees for X-axis labels.
style (
Style) β The default style for the MatPlotLib graphs.theme (
Theme) β The default theme to use for the MatPlotLib graphs.image_type (
ImageType) β The output image format for the graph files.
Create a
MatPlotLibOptionsinstance.To ensure accuracy in graph rendering, the default width, height, and DPI should be set with the width and height being exact multiples of the DPI. This is because the underlying rendering engine uses DPI to determine the pixel dimensions of the output graph from the specified width and height in inches.
If the width and height are not exact multiples of the DPI, it may lead to unexpected scaling or distortion of the graph when rendered, as the rendering engine may round the pixel dimensions to the nearest whole number.
The default values provided here are chosen to balance quality and performance for most common use cases. However, users can customize these values based on their specific requirements for graph resolution and size.
The use of
Nonefor (or, equivalently the omission of) any argument indicates that the default value defined in the next lower precedence level should be used.- Parameters:
width (int | None) β The width in pixels of a MatPlotLib output when rendered. It should be an exact multiple of the dpi and can only be between 500 and 4000 pixels. If
None, the defaultMatPlotLibOptionsdefault width will be used.height (int | None) β The height in pixels of a MatPlotLib output when rendered. It should be an exact multiple of the dpi and can only be between 500 and 4000 pixels. If
None, the defaultMatPlotLibOptionsdefault height will be used.dpi (int | None) β The default DPI (dots per inch) for a MatPlotLib output. It must be between 50 and 400.
y_starts_at_zero (bool | None) β Whether the Y-axis should start at zero.
x_labels_rotation (float | None) β The rotation angle in degrees for X-axis labels.
style (
Style| None) β The default style for the MatPlotLib graphs.theme (
Theme| None) β The theme to use for the MatPlotLib graphs.image_type (
ImageType| None) β The output format for the graph files.
- Raises:
SimpleBenchTypeError β If any of the arguments are of incorrect type.
SimpleBenchValueError β If any of the arguments have invalid values.
- DEFAULT_KWARGS: ClassVar[dict[str, object]] = {'dpi': 150, 'height': 750, 'image_type': ImageType.SVG, 'style': Style.DARK_BACKGROUND, 'theme': {'axes.grid': True, 'axes.labelsize': 16.0, 'axes.titlesize': 20.0, 'figure.dpi': 150.0, 'grid.color': '#444444', 'grid.linestyle': '-', 'legend.fontsize': 14.0, 'legend.framealpha': 1.0, 'legend.shadow': True, 'legend.title_fontsize': 16.0, 'xtick.labelsize': 12.0, 'ytick.labelsize': 12.0}, 'width': 1500, 'x_labels_rotation': 45.0, 'y_starts_at_zero': True}π
Default keyword arguments for
MatPlotLibOptionsconstructor.width: int = 1500height: int = 750dpi: int = 150y_starts_at_zero: bool = Truex_labels_rotation: float = 45.0style:Style=DARK_BACKGROUNDtheme:Theme=DefaultTheme
- property dpi: intπ
Return the Dots Per Inch (DPI) of the graph when rendered.
- Returns:
The default DPI of the graph when rendered.
- Return type:
- classmethod get_default_dpi() int[source]π
Return the default DPI for all MatPlotLib graphs.
If no default DPI has been explicitly set, returns the hardcoded default DPI of 150.
- Returns:
The default DPI for all MatPlotLib graphs.
- Return type:
- classmethod get_default_height() int[source]π
Return the default height in pixels for all MatPlotLib graphs.
If no default height has been explicitly set, returns the hardcoded default height of 750.
- Returns:
The default height in pixels for all MatPlotLib graphs.
- Return type:
- static get_default_image_type() ImageType[source]π
Return the default image type for all MatPlotLib graphs.
If no default image type has been explicitly set, returns
SVG.- Returns:
The default image type for all MatPlotLib graphs.
- Return type:
- classmethod get_default_style() Style[source]π
Return the default style for MatPlotLib graphs.
If no default style has been explictly set, returns the hardcoded built-in
DARK_BACKGROUND.- Returns:
The default style for MatPlotLib graphs.
- Return type:
- classmethod get_default_theme() Theme[source]π
Return the default theme for MatPlotLib graphs.
If no default theme has been explictly set, returns Default.
- Returns:
The default theme for MatPlotLib graphs.
- Return type:
- classmethod get_default_width() int[source]π
Return the default width in pixels for all MatPlotLib graphs.
If no default width has been explicitly set, then it returns the hardcoded default width of 1500.
- Returns:
The default width in pixels for all MatPlotLib graphs.
- Return type:
- classmethod get_default_x_labels_rotation() float[source]π
Return the default rotation angle in degrees for X-axis labels for all MatPlotLib graphs.
If no default has been explicitly set, returns the hardcoded built-in default of 45.0 degrees.
- Returns:
The default rotation angle in degrees for X-axis labels for all MatPlotLib graphs.
- Return type:
- classmethod get_default_y_starts_at_zero() bool[source]π
Return the default value for whether Y-axis starts at zero for all MatPlotLib graphs.
If no default has been explicitly set, returns the hardcoded built-in default of
True.- Returns:
The default value for whether Y-axis starts at zero for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_dpi() int[source]π
Return the hardcoded default DPI for all MatPlotLib graphs.
- Returns:
The hardcoded default DPI for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_height() int[source]π
Return the hardcoded default height in pixels for all MatPlotLib graphs.
- Returns:
The hardcoded default height in pixels for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_image_type() ImageType[source]π
Return the hardcoded default image type for all MatPlotLib graphs.
- Returns:
The hardcoded default image type for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_style() Style[source]π
Return the hardcoded default style for all MatPlotLib graphs.
- Returns:
The hardcoded default style for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_theme() Theme[source]π
Return the hardcoded default theme for all MatPlotLib graphs.
- Returns:
The hardcoded default theme for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_width() int[source]π
Return the hardcoded default width in pixels for all MatPlotLib graphs.
- Returns:
The hardcoded default width in pixels for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_x_labels_rotation() float[source]π
Return the hardcoded default rotation angle in degrees for X-axis labels for all MatPlotLib graphs.
- Returns:
The hardcoded default rotation angle in degrees for X-axis labels for all MatPlotLib graphs.
- Return type:
- classmethod get_hardcoded_default_y_starts_at_zero() bool[source]π
Return the hardcoded default value for whether Y-axis starts at zero for all MatPlotLib graphs.
- Returns:
The hardcoded default value for whether Y-axis starts at zero for all MatPlotLib graphs.
- Return type:
- property height: intπ
Return the height in pixels of the graph when rendered.
- Returns:
The height of the graph in pixels when rendered.
- Return type:
- property image_type: ImageTypeπ
Return the output format for the graph files.
- Returns:
The output image format for the graph files.
- Return type:
- classmethod set_default_dpi( ) None[source]π
Set the default DPI for all MatPlotLib graphs.
If dpi is set to
None, the built-in hardcoded default DPI will be restored.- Parameters:
dpi (int | None) β The DPI to set as the default for MatPlotLib graphs. If
None, the built-in default DPI will be used. The DPI must be between 50 and 400.- Raises:
SimpleBenchTypeError β If the dpi is not an integer or
None.SimpleBenchValueError β If the dpi is not within the valid range.
- classmethod set_default_height( ) None[source]π
Set the default height in pixels for all MatPlotLib graphs.
If height is set to
None, the built-in hardcoded default height will be restored.- Parameters:
height (int | None) β The height to set as the default for MatPlotLib graphs. If
None, the built-in default height will be used. The height must be between 500 and 4000 pixels.- Raises:
SimpleBenchTypeError β If the height is not an integer or
None.SimpleBenchValueError β If the height is not within the valid range.
- static set_default_image_type( ) None[source]π
Set the default image type for all MatPlotLib graphs.
If image_type is set to
None, the built-in default image type will be restored.- Parameters:
image_type (
ImageType| None) β The image type to set as the default for MatPlotLib graphs. IfNone, the built-in default image type will be used.- Raises:
SimpleBenchTypeError β If the image_type is not an
ImageTypeenum member orNone.
- classmethod set_default_style( ) None[source]π
Set the default style/theme for all MatPlotLib graphs.
This static method allows setting a global default style for all MatPlotLib graphs. If set to
None, the build-in hardcoded default MatPlotLib style will be used.- Parameters:
style (
Style| None) β The style to set as the default for MatPlotLib graphs.- Raises:
SimpleBenchTypeError β If the style is not a
Styleenum member orNone.
- classmethod set_default_theme( ) None[source]π
Set the default theme for all MatPlotLib graphs.
This static method allows setting a global default theme for all MatPlotLib graphs. If set to
None, the built-in hardcoded default MatPlotLib theme (DefaultTheme) will be used.- Parameters:
theme (
Theme| None) β The theme to set as the default for MatPlotLib graphs.- Raises:
SimpleBenchTypeError β If the theme is not a
Themeinstance orNone.
- classmethod set_default_width( ) None[source]π
Set the default width in pixels for all MatPlotLib graphs.
- Parameters:
width (int | None) β The width to set as the default for MatPlotLib graphs. If set
None, the built-in hardcoded default width will be restored. The width must be between 500 and 4000 pixels.- Raises:
SimpleBenchTypeError β If the width is not an integer or
None.SimpleBenchValueError β If the width is not within the valid range.
- classmethod set_default_x_labels_rotation( ) None[source]π
Set the default rotation angle in degrees for X-axis labels for all MatPlotLib graphs.
Setting this to
Nonewill restore the default rotation angle of 45.0 degrees.- Parameters:
x_labels_rotation (float | None) β The rotation angle to set as the default for MatPlotLib graphs.
- Raises:
SimpleBenchTypeError β If x_labels_rotation is not a float or
None.
- classmethod set_default_y_starts_at_zero( ) None[source]π
Set the default value for whether Y-axis starts at zero for all MatPlotLib graphs
Setting this to
Nonewill restore the default hardcoded setting of starting the Y-axis at zero.- Parameters:
y_starts_at_zero (bool | None) β The value to set as the default for MatPlotLib graphs.
- Raises:
SimpleBenchTypeError β If y_starts_at_zero is not a bool or
None.
- property style: Styleπ
Return the style for the MatPlotLib graphs.
- Returns:
The style for the MatPlotLib graphs.
- Return type:
- property theme: Themeπ
Return the theme to use for the MatPlotLib graphs.
- Returns:
The theme to use for the MatPlotLib graphs.
- Return type:
- property width: intπ
Return the width in pixels of the graph when rendered.
- Returns:
The width of the graph in pixels when rendered.
- Return type:
- class simplebench.reporters.graph.matplotlib.MatPlotLibReporter(
- config: ReporterConfig,
Bases:
ReporterBase class for MatPlotLib based graph reporters in the
reporterspackage.Initialize the Reporter instance.
- Parameters:
config (ReporterConfig) β The configuration object for the reporter.
- Raises:
SimpleBenchTypeError β If the provided config is not a ReporterConfig instance.
- class simplebench.reporters.graph.matplotlib.Style(value)[source]π
-
Enumeration of graph styles.
Note
The styles correspond to those available in Matplotlib 3.10.6
- BMH = 'bmh'π
Bayesian Methods for Hackers style for graphs.
- CLASSIC = 'classic'π
Light background style for graphs.
Classic matplotlib plotting style
- DARK_BACKGROUND = 'dark_background'π
Dark background style for graphs.
Set black background default line colors to white.
- FIVETHIRTYEIGHT = 'fivethirtyeight'π
FiveThirtyEight style for graphs.
Replicated styles from FiveThirtyEight.com
See dataorigami.net
- GGPLOT = 'ggplot'π
ggplot style for graphs.
Replicates the style of Rβs ggplot library.
See everyhue.me
- GRAYSCALE = 'grayscale'π
Grayscale style for graphs.
Set all colors to grayscale
Note
strings of float values are interpreted by matplotlib as gray values.
- PETTROF10 = 'petroff10'π
Petroff10 style for graphs.
Color cycle survey palette from Petroff (2021):
See arxiv.org and github.com
- SEABORN_V0_8 = 'seaborn-v0_8'π
Base Seaborn style for graphs.
- SEABORN_V0_8_BRIGHT = 'seaborn-v0_8-bright'π
Seaborn bright style for graphs.
- SEABORN_V0_8_COLORBLIND = 'seaborn-v0_8-colorblind'π
Seaborn colorblind style for graphs.
- SEABORN_V0_8_DARK = 'seaborn-v0_8-dark'π
Seaborn dark style for graphs.
- SEABORN_V0_8_DARKGRID = 'seaborn-v0_8-darkgrid'π
Seaborn darkgrid style for graphs.
- SEABORN_V0_8_DARK_PALETTE = 'seaborn-v0_8-dark-palette'π
Seaborn dark palette style for graphs.
- SEABORN_V0_8_DEEP = 'seaborn-v0_8-deep'π
Seaborn deep style for graphs.
- SEABORN_V0_8_MUTED = 'seaborn-v0_8-muted'π
Seaborn muted style for graphs.
- SEABORN_V0_8_NOTEBOOK = 'seaborn-v0_8-notebook'π
Seaborn notebook style for graphs.
- SEABORN_V0_8_PAPER = 'seaborn-v0_8-paper'π
Seaborn paper style for graphs.
- SEABORN_V0_8_PASTEL = 'seaborn-v0_8-pastel'π
Seaborn pastel style for graphs.
- SEABORN_V0_8_POSTER = 'seaborn-v0_8-poster'π
Seaborn poster style for graphs.
- SEABORN_V0_8_TALK = 'seaborn-v0_8-talk'π
Seaborn talk style for graphs.
- SEABORN_V0_8_TICKS = 'seaborn-v0_8-ticks'π
Seaborn ticks style for graphs.
- SEABORN_V0_8_WHITE = 'seaborn-v0_8-white'π
Seaborn white style for graphs.
- SEABORN_V0_8_WHITEGRID = 'seaborn-v0_8-whitegrid'π
Seaborn whitegrid style for graphs.
- SOLARIZE_LIGHT2 = 'Solarize_Light2'π
Solarized light style for graphs.
Solarized color palette taken from ethanschoonover.com
- TABLEAU_COLORBLIND10 = 'tableau-colorblind10'π
Tableau colorblind10 style for graphs.
- class simplebench.reporters.graph.matplotlib.Theme( )[source]π
Bases:
RcParamsAn immutable MatPlotLib base theme class for the graphs.
This is a subclass of
matplotlib.RcParamsthat represents a theme for Matplotlib graphs. It can be used to define custom styles for Matplotlib graphs generated by SimpleBench.See Customizing Matplotlib with style sheets and rcParams for more information on customizing Matplotlib themes.
Initialize a
Themeinstance.- Parameters:
rcparams (dict[str, Any] | None) β The rcParams to use for the theme. If
None, the default Matplotlib rcParams will be used.
Subpackagesπ
- simplebench.reporters.graph.matplotlib.enums package
StyleStyle.BMHStyle.CLASSICStyle.DARK_BACKGROUNDStyle.FIVETHIRTYEIGHTStyle.GGPLOTStyle.GRAYSCALEStyle.PETTROF10Style.SEABORN_V0_8Style.SEABORN_V0_8_BRIGHTStyle.SEABORN_V0_8_COLORBLINDStyle.SEABORN_V0_8_DARKStyle.SEABORN_V0_8_DARKGRIDStyle.SEABORN_V0_8_DARK_PALETTEStyle.SEABORN_V0_8_DEEPStyle.SEABORN_V0_8_MUTEDStyle.SEABORN_V0_8_NOTEBOOKStyle.SEABORN_V0_8_PAPERStyle.SEABORN_V0_8_PASTELStyle.SEABORN_V0_8_POSTERStyle.SEABORN_V0_8_TALKStyle.SEABORN_V0_8_TICKSStyle.SEABORN_V0_8_WHITEStyle.SEABORN_V0_8_WHITEGRIDStyle.SOLARIZE_LIGHT2Style.TABLEAU_COLORBLIND10
- Submodules
- simplebench.reporters.graph.matplotlib.reporter package
- Public API
MatPlotLibOptionsMatPlotLibOptions.DEFAULT_KWARGSMatPlotLibOptions.dpiMatPlotLibOptions.get_default_dpi()MatPlotLibOptions.get_default_height()MatPlotLibOptions.get_default_image_type()MatPlotLibOptions.get_default_style()MatPlotLibOptions.get_default_theme()MatPlotLibOptions.get_default_width()MatPlotLibOptions.get_default_x_labels_rotation()MatPlotLibOptions.get_default_y_starts_at_zero()MatPlotLibOptions.get_hardcoded_default_dpi()MatPlotLibOptions.get_hardcoded_default_height()MatPlotLibOptions.get_hardcoded_default_image_type()MatPlotLibOptions.get_hardcoded_default_style()MatPlotLibOptions.get_hardcoded_default_theme()MatPlotLibOptions.get_hardcoded_default_width()MatPlotLibOptions.get_hardcoded_default_x_labels_rotation()MatPlotLibOptions.get_hardcoded_default_y_starts_at_zero()MatPlotLibOptions.heightMatPlotLibOptions.image_typeMatPlotLibOptions.set_default_dpi()MatPlotLibOptions.set_default_height()MatPlotLibOptions.set_default_image_type()MatPlotLibOptions.set_default_style()MatPlotLibOptions.set_default_theme()MatPlotLibOptions.set_default_width()MatPlotLibOptions.set_default_x_labels_rotation()MatPlotLibOptions.set_default_y_starts_at_zero()MatPlotLibOptions.styleMatPlotLibOptions.themeMatPlotLibOptions.widthMatPlotLibOptions.x_labels_rotationMatPlotLibOptions.y_starts_at_zero
MatPlotLibReporter- Subpackages
- Submodules
- simplebench.reporters.graph.matplotlib.theme package