Miscellaneous

Creating a grid of plots

Casys Tools offers a create_image_grid() utility function to put a set of CasysPlot and/or images together as a grid.
Build an image containing all provided plots in as a grid of plots.

Parameters
----------
figure_size
    Figure size (width, height).
plots
    List of CasysPlots or/and images path.
rows_nb
    Number of rows in the grid.
columns_nb
    Number of columns in the grid.
save_path
    Save individual plot in the specified directory.
dpi
    Resulting image dpi.
kwargs
    Additional parameters passed to the pyplot's figure method.

Returns
-------
:
    Matplotlib figure containing everything.
from casys import CasysPlot, create_image_grid

plot1 = CasysPlot(data=ad, data_name="SIG0 pass", stat="mean")
plot2 = CasysPlot(data=ad, data_name="SIG0 pass", stat="std")
plot3 = CasysPlot(data=ad, data_name="SLA pass", stat="mean")
plot4 = CasysPlot(data=ad, data_name="SLA pass", stat="std")

fig = create_image_grid(
    figure_size=(14.5, 9),
    plots=[plot1, plot2, plot3, plot4],
    columns_nb=2,
)

fig
_images/cp_miscellaneous_2_0.png
The object returned by this function is a Matplotlib Figure and can be used as such once created.

Manually customizing figures

Matplotlib Figure is accessible using the figure property of the CasysPlot object.
The main graphic is the first axes of the figure. Following axes are the additional bars in their addition order.
from casys import CasysPlot, PlotParams

plot = CasysPlot(
    data=ad,
    data_name="SIG0 (6h)",
    stat="mean",
    plot_params=PlotParams(fig_width=8, fig_height=5, y_limits=(8, 17))
)
plot.add_stat_bar(position="top")
plot.show()

fig = plot.figure
fig.suptitle("New title")

ax = fig.axes[0]
ax.grid()
ax.set_ybound(12.5, 15.5)

ax.lines[0].set_marker('.')
ax.lines[0].set_markersize(15)
ax.lines[0].set_linestyle('--')

plot.show()
_images/cp_miscellaneous_3_0.png

Storing and loading

CasysPlot objects can be stored and loaded in order to be shared or reused without having to read, configure or compute everything again.
These operations are done using the store() and load() methods.

Storing method

Store this CasysPlot object into a pickle format.

Parameters
----------
name
    Name and path of the file.
overwrite
    Whether to overwrite any existing file or not.

Example

from casys import CasysPlot

plot = CasysPlot(data=ad, data_name="SIG0 (6h)", stat="mean")

plot.store("plot.back", overwrite=True)

Loading method

Load a previously stored CasysPlot object.

Parameters
----------
name
    Name and path of the file.

Returns
-------
:
    The loaded object.

Example

from casys import CasysPlot

loaded_plot = CasysPlot.load("plot.back")
loaded_plot.show()
_images/cp_miscellaneous_7_0.png

Resetting a plot

CasysPlots might be reset to their original state using the reset() method.
All added elements or merged plots will be removed and parameters set back to the ones used during the initialisation.
Reinitialize this plot by removing anything previously added to
it.