iaf.plot¶
Plotting functions.
- iaf.plot.add_fit(fig: Figure, ax: Axes, x: ndarray | list, y_hat: ndarray | list, a: None | float = None, b: None | float = None, sse: None | float = None, model_for_legend: str = 'linear', legend_location: str = 'best', dpi: int = 150, out_file_name: None | Path | str = None) tuple[source]¶
Add another fit to an existing plot_data() figure.
- Parameters:
fig (Figure) – A matplotlib figure.
ax (Union[np.ndarray, list]) – A matplotlib figure axis.
x (Union[np.ndarray, list]) – List or array of independent values x.
y_hat (Union[np.ndarray, list] (Optional)) – List or array of predicted values y_hat.
a (Union[None, float] (Optional)) – Value of the slope of the predicted line (to be shown in the legend).
b (Union[None, float] (Optional)) – Value of the intercept of the predicted line (to be shown in the legend).
sse (Union[None, float] (Optional)) – Value of the sum of squared difference between y and y_hat (to be shown in the legend).
model_for_legend (str (Optional)) – Set the type of the model to be displayed (based on parameters a and b) in the legend. One of “linear”, “exp”, “log”, “sqrt”; default is “linear”.
legend_location (str (Optional)) – Location of the legend. By default, it is ‘best’. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
dpi (int (Optional)) – Resolution of the figure (please notice, this is set whether the figure is saved or not).
out_file_name (Union[None, Path, str] (Optional)) – Full file name to save the figure. The figure is only displayed if no file name is passed.
- Returns:
handles – Tuple with current figure and axes.
- Return type:
- iaf.plot.imshow(img: ndarray, *, cmap: None | str | ListedColormap = None, auto_stretch: bool = False, clip_percentile: float = 0.0, ax: Axes = None, title: str | None = None, title_font_size: int | None = 10) None[source]¶
Wrapper around matplotlib.pyplot.imshow that allows for toggling intensity stretching, hides axes, maximizes the canvas.
- Parameters:
img (np.ndarray) – 2D image to be displayed. The image can be gray-value (2D array) or RGB. If RGB, it must be in YXC or YXCA format.
cmap (None|str|ListedColormap) – Color map to be used (optional). Only applies to gray-value images and is ignored for RGB images.
auto_stretch (bool) – Whether to auto-stretch intensities for visualisation (optional, default = False). Please notice that this only applies to images of type np.uint8 or np.uint16: float images will always be stretched.
clip_percentile (float (Optional, default = 0.0)) – Percentile to clip intensity in the low and high parts of the dynamic range. Ignored if auto_stretch is False. As for auto_stretch, this only applies to images of type np.uint8 and np.uint16.
ax (matplotlib.axes.Axes (Optional, default = None)) – Axis handle. Pass a valid axes handle to display the image there; if omitted, a new figure and a new set of axes will be created.
title (str) – Title for current axes (optional).
title_font_size (int) – Font size for the title of current axes (optional).
- iaf.plot.plot_data(x: ndarray | list, y: ndarray | list, data_name: str = 'y', x2: None | ndarray | list = None, y_hat: None | ndarray | list = None, a: None | float = None, b: None | float = None, sse: None | float = None, model_for_legend: str = 'linear', errors: None | ndarray | list = None, errors_label: None | str = None, legend_location: str = 'best', label_x: str = 'x', label_y: str = 'y', lim_x: None | tuple = None, lim_y: None | tuple = None, marker_size: int = 100, alpha: float = 0.75, split_series: bool = True, figure_size: tuple = (12, 8), dpi: int = 150, out_file_name: None | Path | str = None) tuple[source]¶
- Flexible plotting function for raw data (single or multiple series),
fitted model (optional) and error bars (optional).
- Parameters:
x (Union[np.ndarray, list]) – List or array of independent values x.
y (Union[np.ndarray, list]) – List or array of dependent/target values y.
data_name (str (Optional, default = "Data")) – Name of the data set to be displayed in the legend.
x2 (Union[None, np.ndarray, list] (Optional)) – List or array of independent values x; it is used to plot the predicted value y_hat. Omit if x2 is the same as x (in the case x is (m x n), x2 will be x[0, :]). If specified, it must be a (1 x n) array.
y_hat (Union[np.ndarray, list] (Optional)) – List or array of predicted values y_hat. If specified, it must be a (1 x n) array.
a (Union[None, float] (Optional)) – Value of the slope of the predicted line (to be shown in the legend).
b (Union[None, float] (Optional)) – Value of the intercept of the predicted line (to be shown in the legend).
sse (Union[None, float] (Optional)) – Value of the sum of squared difference between y and y_hat (to be shown in the legend).
alpha (float (Optional)) – Transparency (between 0.0 and 1.0) for the dots in the scatter plot.
split_series (bool (Optional)) – Set to True (default) to display different series as separate scatter plots with own color, or to False to have them all in one plot (and one color).
model_for_legend (str (Optional)) – Set the type of the model to be displayed (based on parameters a and b) in the legend. One of “linear”, “exp”, “log”, “sqrt”; default is “linear”.
errors (Union[None, np.ndarray, list] (Optional)) – Errors to be plotted on the data. If specified, it must be a (1 x n) array.
errors_label (Union[None, str] = None) – Name of the errors for the legend.
legend_location (str (Optional)) – Location of the legend. By default, it is ‘best’. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
label_x (str (Optional)) – Label of the x-axis (by default it is set to “x”).
label_y (str (Optional)) – Label of the y-axis (by default it is set to “y”).
lim_x (Union[None, tuple] (Optional)) –
By default the extent of the data vector x defines the x-axis limit range. Explicitly set to a tuple (x_min, x_max) to override the x-axis limits. Either one of x_min or x_max can be None if current value should not be changed. In detail: If lim_x is None:
The x-axis range will be defined by the limits of the data vector x.
- If lim_x is (None, None):
The x-axis range will be defined by the limits of everything plotted.
- If lim_x is (0, None):
The x-axis range will be 0 to the higher limit of everything plotted.
- If lim_x is (None, 100):
The x-axis range will from the lower limit of everything plotted to 100.
- If lim_x is (0, 100):
The x-axis range will go from 0 to 100.
lim_y (Union[None, tuple] (Optional)) –
By default the extent of the data vector/array y defines the y-axis limit range. Explicitly set to a tuple (y_min, y_max) to override the y-axis limits. Either one of y_min or y_max can be None if current value should not be changed. In detail: If lim_y is None:
The y-axis range will be defined by the limits of the data vector/array y.
- If lim_y is (None, None):
The y-axis range will be defined by the limits of everything plotted.
- If lim_y is (0, None):
The y-axis range will be 0 to the higher limit of everything plotted.
- If lim_y is (None, 100):
The y-axis range will from the lower limit of everything plotted to 100.
- If lim_y is (0, 100):
The y-axis range will go from 0 to 100.
marker_size (int (Optional)) – Size of the marker. By default, it is set to 100.
split_series – Set to True (default) to display different series as separate scatter plots with own color, or to False to have them all in one plot (and one color).
figure_size (tuple (Optional)) – Size of the figure.
dpi (int (Optional)) – Resolution of the figure (please notice, this is set whether the figure is saved or not).
out_file_name (Union[None, Path, str] (Optional)) – Full file name to save the figure. The figure is only displayed if no file name is passed.
- Returns:
handles – Tuple with current figure and axes.
- Return type:
- iaf.plot.show_labels(labels: ndarray, cmap=None, plot_centroids: bool = False, plot_labels: bool = False, ax: Axes = None, title: str | None = None, title_font_size: float | None = 10.0, label_font_size: float | str | None = 10.0) None[source]¶
Plots a labels image with a suited color map by default.
- Parameters:
labels (np.ndarray) – 2D label image to be displayed. The image must be a label image.
cmap (None|ListedColormap) – Color map to be used (optional). If omitted, a suitable one will be used.
plot_centroids (bool) – Set to True to plot the centroids of the labels. Only one of plot_centroids and plot_labels can be True.
plot_labels (bool) – Set to True to plot the label number on the object. Only one of plot_centroids and plot_labels can be True.
ax (matplotlib.axes.Axes (Optional, default = None)) – Axis handle. Pass a valid axes handle to display the image there; if omitted, a new figure and a new set of axes will be created.
title (str) – Title for current axes (optional).
title_font_size (float) – Font size for the title of current axes (optional).
label_font_size (float|str) – Font size for the labels. It can be either a number or one of {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}
Modules
Utility plotting functions. |
|
Validation plotting functions. |