nested_grid_plotter.NestedGridPlotter#

class nested_grid_plotter.NestedGridPlotter(fig: Figure | None = None, builder: NestedBuilder | None = None)[source]#

Bases: Plotter

Alias 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:

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_subplot_names_are_unique()

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_grid_and_tick_prams_to_all_axes([...])

Add a grid to all the axes of the figure.

clear_all_axes()

Clear all the axes from their data and layouts.

clear_fig_legends()

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:
  • fig_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.

  • remove_duplicates (bool, optional) – Whether to remove duplicated handle-label couples. The default is True.

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.

Parameters:

ax_name (str) – Name of the axis.

Returns:

Handles and labels lists.

Return type:

Tuple[List[Artist], List[str]]

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:
  • ax_name (str) – Ax for which to add the legend.

  • 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:

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.

Parameters:
  • ax_name (str) – Ax for which to add the item.

  • handle (Any) – Handle to add to the legend.

  • label (str) – Label associated to the given handle.

Return type:

None

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.

clear_fig_legends() None#

Remove all added figure legends

close() None#

Close the current figure.

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

identify_axes(fontsize: int = 48) None#

Draw the label in a large font in the center of the Axes.

Parameters:
  • ax_dict (Dict[str, Axes]) – Mapping between the title / label and the Axes.

  • fontsize (int, optional) – How big the label should be.

Return type:

None

savefig(*args: Any, **kwargs: Any) None#

Save the current figure.

Parameters:
Return type:

None

property ax_dict: Dict[str, Axes]#

Return a flatten version of grouped_ax_dict.

property axes: List[Axes]#

Return all axes as a list.

property axes_names: List[str]#

Return all axes names as a list.

property sf_dict: Dict[str, SubFigure]#

Return a flatten version of grouped_sf_dict.