nested_grid_plotter.NestedGridPlotter#
- class nested_grid_plotter.NestedGridPlotter(fig: Figure | None = None, builder: NestedBuilder | None = None)[source]#
Bases:
PlotterAlias for Plotter for backward compatibility.
- __init__(fig: Figure | None = None, builder: NestedBuilder | None = None) None#
Initiate the instance.
- Parameters:
fig (Optional[Figure]) – Figure for the plot. One can either use matplotlib.pyplot.figure(…) or matplotlib.figure.Figure. If None, matplotlib.pyplot.figure(…) is used. The default is None.
builder (Optional[NestedBuilder]) – Builder to populate the figure with subfgures and axes. See :class:`SubfigsBuilder`_ and :class:`SubplotsMosaicBuilder`_.
- Variables:
fig (
matplotlib.figure.Figure) – Description.subfigs (Dict[str,
matplotlib.figure.SubFigure]) – Description.ax_dict (Dict[str, Dict[str, Axes]]) – Nested dict, first level with subfigures names and second with axes names.
Public methods summary
__delattr__(name, /)Implement delattr(self, name).
__dir__()Default dir() implementation.
__eq__(value, /)Return self==value.
__format__(format_spec, /)Default object formatter.
__ge__(value, /)Return self>=value.
__getattribute__(name, /)Return getattr(self, name).
__getstate__()Helper for pickle.
__gt__(value, /)Return self>value.
__hash__()Return hash(self).
__init__([fig, builder])Initiate the instance.
__init_subclass__()This method is called when a class is subclassed.
__le__(value, /)Return self<=value.
__lt__(value, /)Return self<value.
__ne__(value, /)Return self!=value.
__new__(*args, **kwargs)__reduce__()Helper for pickle.
__reduce_ex__(protocol, /)Helper for pickle.
__repr__()Return repr(self).
__setattr__(name, value, /)Implement setattr(self, name, value).
__sizeof__()Size of object in memory, in bytes.
__str__()Return str(self).
__subclasshook__(object, /)Abstract classes can override this to customize issubclass().
Check if a subplot name is not used in two different subfigures.
_gather_figure_legend_items([fig_name, ...])Gather the legend items from all axes of the figure or of one subfigure.
_get_axis_legend_items(ax_name)Get the given axis legend handles and labels.
_get_bbox_extra_artists([kwargs])_iterate_subfig_grouped_axes(subfig_name)_remove_dulicated_legend_items(handles, labels)Remove the duplicated legend handles and labels.
add_axis_legend(ax_name[, is_reverse_items])Add a legend to the graphic.
add_axis_legend_outside_frame(ax_name[, ...])Add a legend to the ax outside the ax frame.
add_extra_legend_item(ax_name, handle, label)Add an extra legend item to the given axis.
add_fig_legend([name, bbox_x_shift, ...])Add a legend to the plot.
Add a grid to all the axes of the figure.
Clear all the axes from their data and layouts.
Remove all added figure legends
close()Close the current figure.
get_axes(ax_names)Get a sequence of axes from the plotter.
get_axis(ax_name)Get an axis from the plotter.
get_subfigure(subfig_name)Get an axis from the plotter.
get_subfigure_ax_dict(subfig_name)identify_axes([fontsize])Draw the label in a large font in the center of the Axes.
savefig(*args, **kwargs)Save the current figure.
Methods definition
- static _remove_dulicated_legend_items(handles: Sequence[Artist], labels: Sequence[str]) Tuple[List[Artist], List[str]]#
Remove the duplicated legend handles and labels.
- _check_if_subplot_names_are_unique() None#
Check if a subplot name is not used in two different subfigures.
This is necessary otherwise, one or more subplots would be missing from the ax_dict.
- Raises:
Exception – Indicate which axis names are duplicated and on which subfigures .
- Return type:
None
- _gather_figure_legend_items(fig_name: str | None = None, remove_duplicates: bool = True) Tuple[List[Artist], List[str]]#
Gather the legend items from all axes of the figure or of one subfigure.
- Parameters:
- Returns:
Handles and labels lists.
- Return type:
Tuple[List[Artist], List[str]]
- _get_axis_legend_items(ax_name: str) Tuple[List[Artist], List[str]]#
Get the given axis legend handles and labels.
- add_axis_legend(ax_name: str, is_reverse_items: bool = False, **kwargs: Any) Tuple[List[Any], List[str]]#
Add a legend to the graphic.
- Parameters:
- Returns:
Tuple of list of handles and list of associated labels.
- Return type:
(Tuple[List[Any], List[str]])
- add_axis_legend_outside_frame(ax_name: str, bbox_x_shift: float | None = None, bbox_y_shift: float | None = None, loc: Literal['left', 'right', 'top', 'bottom'] = 'bottom', borderaxespad: float = 1.0, is_reverse_items: bool = False, **kwargs: Any) Legend | None#
Add a legend to the ax outside the ax frame.
- Parameters:
ax_name (str) – The name of the ax for which to add a legend outside the frame.
bbox_x_shift (float, optional) – Legend vertical shift (up oriented). The default is 0.0.
bbox_y_shift (float, optional) – Legend horizontal shift (right oriented). The default is 0.0.
loc (Literal["left", "right", "top", "bottom"], optional) – Side on which to place the legend box. The default is “bottom”.
is_reverse_items (bool) – Whether to reverse the order of items in the legend. The default is False. .. versionadded:: 2.0
**kwargs (Any) – Additional arguments for plt.legend.
- Returns:
The created legend instance. None if no handles nor labels have been found.
- Return type:
Optional[Legend]
- add_extra_legend_item(ax_name: str, handle: Any, label: str) None#
Add an extra legend item to the given axis.
- add_fig_legend(name: str | None = None, bbox_x_shift: float = 0.0, bbox_y_shift: float = 0.0, loc: Literal['left', 'right', 'top', 'bottom'] = 'bottom', is_reverse_items: bool = False, **kwargs: Any) Legend | None#
Add a legend to the plot.
To the main figure or to one subfigure.
- Parameters:
name (Optional[str], optional) – The subfigure to which add the legend. If no name is given, it applies to the all figure. Otherwise to a specific subfigure. The default is None.
bbox_x_shift (float, optional) – Legend vertical shift (up oriented). The default is 0.0.
bbox_y_shift (float, optional) – Legend horizontal shift (right oriented). The default is 0.0.
loc (Literal["left", "right", "top", "bottom"], optional) – Side on which to place the legend box. The default is “bottom”.
is_reverse_items (bool) – Whether to reverse the order of items in the legend. The default is False. .. versionadded:: 2.0
**kwargs (Any) – Additional arguments for plt.legend.
- Returns:
The created legend instance. None if no handles nor labels have been found.
- Return type:
Optional[Legend]
- add_grid_and_tick_prams_to_all_axes(subfigure_name: str | None = None, **kwargs: Any) None#
Add a grid to all the axes of the figure.
- Parameters:
subfigure_name (Optional[str], optional) – Name of the target subfigure. If None, apply to the all figure. The default is None.
**kwargs (Any) – Keywords for add_grid_and_thick_prams_to_axis.
- Return type:
None
- clear_all_axes() None#
Clear all the axes from their data and layouts.
It also resets the additional handles and labels for the legend.
- get_axes(ax_names: Sequence[str]) List[Axes]#
Get a sequence of axes from the plotter.
- Parameters:
ax_names (Sequence[str]) – Name of the axes to get. Must be iterable.
- Returns:
The desired axes.
- Return type:
Axes
- get_axis(ax_name: str) Axes#
Get an axis from the plotter.
- Parameters:
ax_name (str) – Name of the axis to get.
- Returns:
The desired axis.
- Return type:
Axes
- get_subfigure(subfig_name: str) SubFigure#
Get an axis from the plotter.
- Parameters:
subfig_name (str) – Name of the subfigure to get.
- Returns:
The desired subfigure.
- Return type:
SubFigure
- savefig(*args: Any, **kwargs: Any) None#
Save the current figure.
- Parameters:
*args (Any) – Positional arguments for
matplotlib.figure.Figure.savefig().**kwargs (Any) – Keywords arguments for
matplotlib.figure.Figure.savefig().
- Return type:
None