neuralib.plot.tools.AxesExtendHelper

class neuralib.plot.tools.AxesExtendHelper[source]

Bases: object

Add a child inset Axes to this existing Axes

Example of add hist:

>>> from neuralib.plot import plot_figure

>>> x = np.random.sample(10)
>>> y = np.random.sample(10)
>>> with plot_figure(None) as ax:
...     ax.plot(x, y, 'k.')
...     helper = AxesExtendHelper(ax)
...     helper.xhist(x, bins=10)
...     helper.yhist(y, bins=10)

Example of add bar:

>>> from neuralib.plot import plot_figure
>>> img = np.random.sample((10, 10))
>>> with plot_figure(None) as ax:
...     ax.imshow(img)
...     helper = AxesExtendHelper(ax)
...     x = y = np.arange(10)
...     helper.xbar(x, np.mean(img, axis=0), align='center')
...     helper.ybar(y, np.mean(img, axis=1), align='center')
__init__(ax, mode='both')[source]
Parameters:
  • ax (Axes) – matplotlib.axes.Axes

  • mode (Literal['both', 'x', 'y']) – extended axis {‘both’, ‘x’, ‘y’}. default is to add both

ax_x: Axes | None
ax_y: Axes | None
xhist(values, bins, **kwargs)[source]

x axis histogram

Parameters:
  • values (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series) – histogram x axis

  • bins (int | Sequence[float] | str | None) – number of bins

  • kwargs – additional arguments passed to Axes.hist()

yhist(values, bins, **kwargs)[source]

y axis histogram

Parameters:
  • values (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series) – histogram x axis

  • bins (int | Sequence[float] | str | None) – number of bins

  • kwargs – additional arguments passed to Axes.hist()

xbar(x, height, width=None, **kwargs)[source]

x axis bar

Parameters:
  • x (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series) – x axis

  • height (ndarray) – bar height

  • width (float | ndarray | None) – bar width

  • kwargs – additional arguments passed to Axes.bar()

ybar(y, width, height=None, **kwargs)[source]

y axis bar

Parameters:
  • y (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series) – y axis

  • height (float | ndarray | None) – bar height

  • width (ndarray) – bar width

  • kwargs – additional arguments passed to Axes.bar()