From 850bfaf4c9b9770d5f47121f5fb643a3be777cd8 Mon Sep 17 00:00:00 2001 From: Julius <juliusflorstedt@gmail.com> Date: Mon, 17 Mar 2025 10:57:00 +0100 Subject: [PATCH 1/4] updated file write --- plot_serializer/serializer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plot_serializer/serializer.py b/plot_serializer/serializer.py index 023e96b..6955dee 100644 --- a/plot_serializer/serializer.py +++ b/plot_serializer/serializer.py @@ -418,7 +418,9 @@ class Serializer: if self._written_to_file: raise NotImplementedError("You can only write the figure into the JSON once! Multiple tries were attempted") if isinstance(file, str): - os.makedirs(os.path.dirname(file), exist_ok=True) + directory = os.path.dirname(file) + if directory: + os.makedirs(directory, exist_ok=True) with open(file, "w") as file: self.write_json_file(file) else: -- GitLab From 851098afad83672ea9d870962c82e65ded95d975 Mon Sep 17 00:00:00 2001 From: Julius <juliusflorstedt@gmail.com> Date: Mon, 17 Mar 2025 10:58:35 +0100 Subject: [PATCH 2/4] revert --- plot_serializer/serializer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plot_serializer/serializer.py b/plot_serializer/serializer.py index 6955dee..023e96b 100644 --- a/plot_serializer/serializer.py +++ b/plot_serializer/serializer.py @@ -418,9 +418,7 @@ class Serializer: if self._written_to_file: raise NotImplementedError("You can only write the figure into the JSON once! Multiple tries were attempted") if isinstance(file, str): - directory = os.path.dirname(file) - if directory: - os.makedirs(directory, exist_ok=True) + os.makedirs(os.path.dirname(file), exist_ok=True) with open(file, "w") as file: self.write_json_file(file) else: -- GitLab From 93f9b2cf78d0a9650a0668cd5c604b3a8d38b229 Mon Sep 17 00:00:00 2001 From: Julius <juliusflorstedt@gmail.com> Date: Sun, 30 Mar 2025 12:11:00 +0200 Subject: [PATCH 3/4] added doc for write to paths --- doc/output.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/output.rst b/doc/output.rst index 9885e73..0984db5 100644 --- a/doc/output.rst +++ b/doc/output.rst @@ -9,6 +9,12 @@ The JSON string can be accessed via the ``to_json()``-Method on the serializer o serializer.to_json() serializer.write_json_file("test_plot.json") +Writing to paths is also supported, with directories being created if they do not exist. + +.. code-block:: python + + serializer.write_json_file("some_dir/test_plot.json") + Serializing to RO-Crate ----------------------- PloSe allows you to store your plot as an `RO-Crate <https://www.researchobject.org/ro-crate/>`_. -- GitLab From c844d650ec691e7489939e1c8dfcfa3fcfb50b19 Mon Sep 17 00:00:00 2001 From: Julius <juliusflorstedt@gmail.com> Date: Sun, 30 Mar 2025 17:33:33 +0200 Subject: [PATCH 4/4] added doc for plt vs serializer --- doc/howitworks.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/howitworks.rst b/doc/howitworks.rst index fd05a1c..619bc62 100644 --- a/doc/howitworks.rst +++ b/doc/howitworks.rst @@ -164,9 +164,17 @@ This information about the color relates to each trace, so to inspect it in the ] +Using Serializer object vs. matplotlib.pyplot +------------------------------------------ +So far the Serializer class for Matplotlib only supports the subplots and show method, meaning any other operations on the pyplot object will not get serialized and making +such changes to your plot still requires calling the functions on the pyplot object. The reason for this being that the Serializer was not implemented as a fully functional proxy +for the pyplot object like the AxesProxy class is for Axes of matplotlib.axes. + + + What gets serialized -------------------- -PlotSerializer always reads out the main arguments of the plot. Further serialized keyword parameters will be specifically noted. +PlotSerializer in general always reads out the main arguments of the plot function. Further serialized keyword parameters will be specifically noted. As a rule of thumb most options to change the style and look of a diagram will not be serialized and can even distort the data inside the JSON file. Similarly beware of modifying diagrams after creating them. An example of this would be you taking the returned objects of these methods and calling further functions on them, modyfying their attributes. -- GitLab