plot_serializer.matplotlib.serializer.MatplotlibSerializer#

class plot_serializer.matplotlib.serializer.MatplotlibSerializer[source]#

Bases: Serializer

Serializer specific to matplotlib. Most of the methods on this object mirror the matplotlib.pyplot api from matplotlib.

Parameters:

Serializer (_type_) – Parent class

Methods

add_custom_metadata_axis

add_custom_metadata_datapoints

add_custom_metadata_figure

Adds a piece of custom metadata to the generated figure object.

add_custom_metadata_plot

add_custom_metadata_trace

add_to_ro_crate

Adds the figure from this serializer to the specified ro-crate as a json file.

check_collected_and_written

serialized_figure

Returns a figure object that contains all the data that has been captured by this serializer so far.

show

subplots

to_json

Returns the data that has been collected so far as a json-encoded string.

write_json_file

Writes the collected data as json to a file on disk.

add_custom_metadata_figure(dict: Mapping[str, int | float | str]) None#

Adds a piece of custom metadata to the generated figure object. All metadata for each object is uniquely identified by a name for that piece of metadata. If a name that already exists on this object is provided, the previously set value will be overridden.

Parameters:
  • name (str) – Unique name of this piece of metadata

  • value (MetadataValue) – Value that this piece of metadata should have

add_to_ro_crate(crate_path: str | Path, file_path: str, *, create: bool = True, name: str | None = None) None#

Adds the figure from this serializer to the specified ro-crate as a json file. If the specified ro-crate does not exist, by default, a new one will be created.

If no name is explicitly specified, the name of the figure is used instead. If the figure has no name, the name of the file specified in file path is used.

Parameters:
  • crate_path (Union[str, Path]) – Path to the root folder of the ro-crate.

  • file_path (str) – File path within the ro-crate where the file is placed (excluding the path to the ro-crate itself).

  • create (bool) – Whether to create the ro-crate if it doesn’t exist. Defaults to True.

  • name (Optional[str], optional) – Name of the ro-crate. Defaults to None.

serialized_figure() Figure#

Returns a figure object that contains all the data that has been captured by this serializer so far. The figure object is guaranteed to not change further after it has been returned.

Returns:

Figure object

Return type:

Figure

to_json(*, emit_warnings: bool = True) str#

Returns the data that has been collected so far as a json-encoded string.

Parameters:

emit_warnings (bool) – If set to True (default), warnings about missing graph properties will be logged

Returns:

Json string

Return type:

str

write_json_file(file: TextIO | str, *, emit_warnings: bool = True) None#

Writes the collected data as json to a file on disk.

Parameters:
  • file (Union[TextIO, str]) – Either a filepath as string or a TextIO object

  • emit_warnings (bool) – If set to True (default), warnings about missing graph properties will be logged