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 frommpl_toolkits.axes_grid1.make_axes_locatable()
to add new axes to the figure. Clients can calladd_ax()
to add a new axis.All the axes in the ExtendableFigure can be accessed by name using a dict- like interface:
f[name]
wheref
is the ExtendableFigure instance andname
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]
wheref
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
- name (str) – A name for the new axis. The axis will be accessible as
-
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]
wheref
is this ExtendableFigure instance.
-