plot_serializer.serializer.Serializer#
- class plot_serializer.serializer.Serializer[source]#
Bases:
object
A Serializer is an object that has a subclass for different libraries (e.g. MatplotlibSerializer). The Serializer allows you to use a library like you would normally, while collecting all the data you specify inside the plotting library and providing methods for serializing that information to json.
Methods
add_custom_metadata_axis
add_custom_metadata_datapoints
Adds a piece of custom metadata to the generated figure object.
add_custom_metadata_plot
add_custom_metadata_trace
Adds the figure from this serializer to the specified ro-crate as a json file.
check_collected_and_written
Returns a figure object that contains all the data that has been captured by this serializer so far.
Returns the data that has been collected so far as a json-encoded string.
Writes the collected data as json to a file on disk.
- add_custom_metadata_figure(dict: Mapping[str, int | float | str]) None [source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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