cdiutils.interactive.Plotter#
- class cdiutils.interactive.Plotter(data, plot='slices', log=False, cmap='turbo', figsize=(10, 10), fontsize=15, title=None)[source]#
Class to plot data from files or Numpy arrays.
- Parameters:
data (str | ndarray) – The data to plot. This can either be the path to a file, or a Numpy array directly.
plot (str) – Specifies the type of plot to create. Available options are: ‘2D’, ‘slices’, “phase_slices”, ‘contour_slices’, ‘sum_slices’, ‘sum_contour_slices’, ‘3D’, “1D”, by default ‘slices’.
log (bool) – Whether to display the plot in log scale, by default False.
cmap (str) – The colourmap to use for the plot, by default ‘turbo’.
figsize (tuple[int, int]) – The size of the figure in inches, by default (10, 10).
fontsize (int) – The font size to use in the plot, by default 15.
title (str) – The title of the plot, by default None.
- data_array#
The Numpy array with the data.
- plot#
The type of plot specified.
- log#
Whether to display the plot in log scale.
- cmap#
The colourmap specified.
- figsize#
The size of the figure specified.
- fontsize#
The font size specified.
- title#
The title of the plot.
- filename#
The name of the file if data is given as a path.
- __init__(data, plot='slices', log=False, cmap='turbo', figsize=(10, 10), fontsize=15, title=None)[source]#
Initialise the Plotter class.
- Parameters:
data (str | ndarray) – The data to plot. This can either be the path to a file, or a Numpy array directly.
plot (str) – Specifies the type of plot to create. Available options are: ‘2D’, ‘slices’, “phase_slices”, ‘contour_slices’, ‘sum_slices’, ‘sum_contour_slices’, ‘3D’, “1D”, by default ‘slices’.
log (bool) – Whether to display the plot in log scale, by default False.
cmap (str) – The colourmap to use for the plot, by default ‘turbo’.
figsize (tuple[int, int]) – The size of the figure in inches, by default (10, 10).
fontsize (int) – The font size to use in the plot, by default 15.
title (str) – The title of the plot, by default None.
- init_plot()[source]#
Initialise a plot of the data stored in the data_array attribute.
The type of plot and the parameters are specified in the class constructor. The plot can be a 2D plot, 3D slices, contour plots of slices, sum of slices, sum of contour plots of slices, or a 3D plot. The specific plot type is determined by the value of the plot attribute. If the number of dimensions of the data_array is not compatible with the specified plot type, the function simply prints the number of dimensions and shape of the data_array.
- data_array#
An array containing the data to be plotted.
- plot#
The type of plot to be generated, which can be one of the following: “2D”, “slices”, “phase_slices”, “contour_slices”, “sum_slices”, “sum_contour_slices”, or “3D”.
- figsize#
The size of the plot in inches.
- fontsize#
The font size of the plot.
- log#
If True, plot the data in logarithmic scale.
- cmap#
The colourmap to be used for the plot.
- title#
The title of the plot.
- get_data_array()[source]#
Return the data array stored in the class instance by reading the specified file.
The file must have a .npy, .cxi, .h5, or .npz extension. If the file is a .npy or .h5 file, the data array is directly loaded. If the file is a .cxi file, the data array is loaded from f.root.entry_1.data_1.data[:] or f.root.entry_1.image_1.data[:], following cxi conventions. If the file is a .npz file, the user is prompted to select the data array from a dropdown list of arrays stored in the .npz file.
If the file extension is supported and the data array is successfully loaded, the init_plot function is called.
- Returns:
A Numpy array representing the data stored in the class, or None if the file could not be loaded.
- Raises:
KeyError – If the file is a .cxi or .h5 file, and the data
could not be found in either `f.root.entry_1.data_1.data[ –
]`
or `f.root.entry_1.image_1.data[ –
]`.