pylbo.visualisation.figure_window

Classes

FigureWindow

Class to handle the top-level creation of figure windows. Assigns unique figure

InteractiveFigureWindow

Subclass to handle interactivity in the figure windows.

Module Contents

class pylbo.visualisation.figure_window.FigureWindow(fig: matplotlib.figure.Figure)

Class to handle the top-level creation of figure windows. Assigns unique figure ids and takes care of figure, axes, and gridspec management.

Parameters:

fig (Figure) – The figure object.

fig

The figure object.

Type:

Figure

figsize

The size of the figure in inches.

Type:

tuple[int, int]

figure_id

The unique figure id.

Type:

str

figure_stack
fig
figsize
figure_id
_figure_drawn = False
property figure_ids: list[str]

Returns the list of figure ids.

create_default_figure(figlabel: str, figsize: tuple[int, int]) tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

Creates a default figure with a 1x1 subplot.

Parameters:
  • figlabel (str) – The label of the figure.

  • figsize (tuple[int, int]) – The size of the figure.

Returns:

  • fig (~matplotlib.figure.Figure) – The figure on which to draw.

  • ax (~matplotlib.axes.Axes) – The axes on which to draw.

_generate_figure_id(figlabel: str) str

Generates a unique figure id.

Parameters:

figlabel (str) – The label of the figure.

Returns:

figure_id – The unique figure id of the form “figure_type-x” where x is an integer.

Return type:

str

make_layout_tight() None

Calls tight_layout() on a figure and captures the userwarning introduced in matplotlib 3.5.

add_to_stack() None

Adds the figure to the stack.

add_subplot_axes(ax: matplotlib.axes.Axes, loc: str = 'right', share: str = None, apply_tight_layout: bool = True)

Adds a new subplot to a given matplotlib subplot, essentially “splitting” the axis into two. Position and placement depend on the loc argument. When called on a more complex subplot layout the overall gridspec remains untouched, only the ax object has its gridspec modified. On return, tight_layout() is called by default to prevent overlapping labels.

Parameters:
  • ax (Axes) – The axes object, this will be “split” and a new axes will be added to the figure.

  • loc (str) – The location of the new axes. Should be one of “left”, “right”, “top”, “bottom”. Defaults to “right”.

  • share (str) – Can be “x”, “y” or “all”. This locks axes zooming between both subplots.

  • apply_tight_layout (bool) – Whether to call tight_layout() on the figure before return.

Raises:

ValueError – If the loc argument is invalid.

Returns:

The axes instance that was added.

Return type:

Axes

draw() None
redraw() None
save(filename: str, **kwargs) None

Saves the current figure.

Parameters:
  • filename (str, PathLike) – The filename to which the current figure is saved.

  • kwargs – Default keyword arguments passed to savefig().

show()

Shows the selected figure

class pylbo.visualisation.figure_window.InteractiveFigureWindow(fig: matplotlib.figure.Figure)

Bases: FigureWindow

Subclass to handle interactivity in the figure windows.

_mpl_callbacks = []
redraw() None
connect_callbacks() None

Connects all callbacks to the canvas

disconnect_callbacks() None

Disconnects all callbacks from the canvas

make_legend_interactive(legendhandler: pylbo.visualisation.legend_handler.LegendHandler) None

Makes the legend interactive.

Parameters:

legendhandler (LegendHandler) – The legend handler.

add_eigenfunction_interface(efhandler: pylbo.visualisation.eigenfunctions.eigfunc_interface.EigenfunctionInterface) None

Adds an eigenfunction interface to the figure.

Parameters:
  • efhandler ()

  • EigenfunctionInterface – The eigenfunction interface.