Figure#

class anyplotlib.figure.Figure(**kwargs)[source]#

Bases: AnyWidget

Multi-panel interactive figure widget.

Create via subplots() or directly:

fig = Figure(2, 2, figsize=(800, 600))
ax  = fig.add_subplot((0, 0))
v2d = ax.imshow(data)
layout_json#

A trait for unicode strings.

event_json#

A trait for unicode strings.

fig_width#

An int trait.

fig_height#

An int trait.

add_subplot(spec)[source]#

Add a subplot cell and return its Axes.

Parameters:

spec (SubplotSpec | int | (row, col) tuple) –

  • SubplotSpec: used directly (e.g. from GridSpec[r, c]).

  • int: converted to (row, col) via divmod(spec, ncols), matching matplotlib.Figure.add_subplot(num) numbering.

  • (row, col) tuple: selects a single cell.

Return type:

Axes

get_axes()[source]#
Return type:

list

class anyplotlib.figure.GridSpec(nrows, ncols, *, width_ratios=None, height_ratios=None)[source]#

Bases: object

Define a grid of subplot cells.

Parameters:
  • nrows (int) – Grid dimensions.

  • ncols (int) – Grid dimensions.

  • width_ratios (list of float, optional) – Relative column widths (length ncols). Defaults to equal widths.

  • height_ratios (list of float, optional) – Relative row heights (length nrows). Defaults to equal heights.

Examples

>>> gs = GridSpec(2, 3, width_ratios=[2, 1, 1])
>>> spec = gs[0, :]          # top row spanning all columns
>>> spec = gs[1, 1:3]        # bottom-right 2 columns
class anyplotlib.figure.SubplotSpec(gs, row_start, row_stop, col_start, col_stop)[source]#

Bases: object

Describes which grid cells a subplot occupies.

Parameters:
anyplotlib.figure.subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, figsize=(640, 480), width_ratios=None, height_ratios=None, gridspec_kw=None)[source]#

Create a Figure and a grid of Axes.

Mirrors matplotlib.pyplot.subplots().

Parameters:
  • nrows (int) – Number of rows and columns in the grid.

  • ncols (int) – Number of rows and columns in the grid.

  • sharex (bool) – Link pan/zoom across all panels on the respective axis.

  • sharey (bool) – Link pan/zoom across all panels on the respective axis.

  • figsize ((width, height)) – Figure size in CSS pixels. Default (640, 480).

  • width_ratios (list of float, optional) – Relative column widths. Equivalent to gridspec_kw={"width_ratios": ...}.

  • height_ratios (list of float, optional) – Relative row heights. Equivalent to gridspec_kw={"height_ratios": ...}.

  • gridspec_kw (dict, optional) – Extra keyword arguments forwarded to GridSpec. Recognised keys: width_ratios, height_ratios.

Returns:

  • fig (Figure)

  • axs (Axes or numpy array of Axes) –

    • Single cell → scalar Axes.

    • Single row → 1-D array of shape (ncols,).

    • Single column → 1-D array of shape (nrows,).

    • Otherwise → 2-D array of shape (nrows, ncols).

Examples

>>> import anyplotlib as vw
>>> import numpy as np
>>> fig, axs = vw.subplots(2, 1, figsize=(640, 600))
>>> v2d = axs[0].imshow(np.random.rand(128, 128))
>>> v1d = axs[1].plot(np.sin(np.linspace(0, 6.28, 256)))
>>> fig