lib5c.plotters.extendable.extendable_figure module

Module for the ExtendableFigure base class.

class lib5c.plotters.extendable.extendable_figure.ExtendableFigure[source]

Bases: object

Base class for figures that can interactively and sequentially tack on new axes to themselves.

Uses a divider attribute obtained from mpl_toolkits.axes_grid1.make_axes_locatable() to add new axes to the figure. Clients can call add_ax() to add a new axis.

All the axes in the ExtendableFigure can be accessed by name using a dict- like interface: f[name] where f is the ExtendableFigure instance and name is the name of the axis. The ExtendableFigure starts out with one axis already present, called ‘root’.

axes

The collection of named Axes represented by this object.

Type

dict of matplotlib.axes.Axes

fig

The Figure instance this object represents.

Type

matplotlib.figure.Figure

divider

This object serves as a coordinator for the allocation of new Axes to be appended to this ExtendableFigure.

Type

mpl_toolkits.axes_grid1.axes_divider.AxesDivider

Examples

>>> import numpy as np
>>> from lib5c.plotters.extendable.extendable_figure import ExtendableFigure
>>> xs = np.arange(0, 10)
>>> f = ExtendableFigure()
>>> f['root'].imshow(np.arange(100).reshape((10,10)))
<matplotlib.image.AxesImage object at ...>
>>> f.add_ax('sin')
<matplotlib.axes._axes.Axes object at ...>
>>> f['sin'].plot(xs, np.sin(xs))
[<matplotlib.lines.Line2D object at ...>]
>>> f.add_colorbar('root')
>>> f.save('test/extendablefigure.png')
add_ax(name, loc='bottom', size='10%', pad=0.1)[source]

Adds a new axis to this ExtendableFigure.

Parameters
  • name (str) – A name for the new axis. The axis will be accessible as f[new_ax_name] where f is this ExtendableFigure instance.

  • loc ({'top', 'bottom', 'left', 'right'}) – Which side of the figure to add the new axis to.

  • size (str) – The size of the new axis as a percentage of the main figure size. Should be passed as a string ending in ‘%’.

  • pad (float) – The padding to use between the existing parts of the figure and the newly added axis.

Returns

The newly created axis.

Return type

pyplot axis

add_colorbar(source_ax_name, loc='right', size='10%', pad=0.1, new_ax_name='colorbar')[source]

Adds a colorbar to the heatmap in a new axis.

Parameters
  • source_ax_name (str) – The name of the axis that this should be the colorbar for. This is where matplotlib will look to find color information for the new colorbar.

  • loc ({'top', 'bottom', 'left', 'right'}) – Which side of the figure to add the new colorbar to.

  • size (str) – The size of the new axis as a percentage of the main figure size. Should be passed as a string ending in ‘%’.

  • pad (float) – The padding to use between the existing parts of the figure and the newly added axis.

  • new_ax_name (str) – A name for the new axis. The axis will be accessible as f[new_ax_name] where f is this ExtendableFigure instance.

close()[source]

Clears and closes the pyplot figure related to this ExtendableFigure.

save(filename)[source]

Saves this ExtendableHeatmap to the disk as an image file.

Parameters

filename (str) – The filename to save the image to.