neuralib.plot.figure
- neuralib.plot.figure.plot_figure(output, *args, set_square=False, set_equal_scale=False, win_backend='QtCairo', dpi=None, default_style=True, tight_layout=True, font_sans_serif='Arial', **kwargs)[source]
Context manager for creating and saving a matplotlib figure
Example
>>> fig_output = Path('output.png') >>> with plot_figure(fig_output) as ax: ... ax.plot([0, 10], [0, 10])
generate output.png
- Parameters:
output (Path | None) – Path to save the output figure. If None, the figure will be shown.
args – Arguments for
plt.subplots()set_square (bool) – If True, set the plot to be square
set_equal_scale (bool) – If True, set equal scaling for x and y axes
win_backend (Literal['GTK3Agg', 'GTK3Cairo', 'GTK4Agg', 'GTK4Cairo', 'MacOSX', 'nbAgg', 'QtAgg', 'QtCairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo'] | None) – Backend to handle backend issues in Windows If high resolution image (WXAgg), otherwise keep normal pdf output (WXCario)
dpi (int | None) – DPI for saving the figure
default_style (bool) – If True, apply default style to the axes
tight_layout (bool) – If True, apply tight layout to the figure
font_sans_serif (str | None) – Font style. If None, then use default from mplrc
kwargs – Additional keyword arguments for
plt.subplots()
- Returns:
Single or array of matplotlib Axes object
- Return type:
ContextManager[Axes] | ContextManager[ndarray[Any, dtype[Axes]]]
- neuralib.plot.figure.ax_set_default_style(ax)[source]
Default Axes style
- Parameters:
ax (Axes) –
Axes
- neuralib.plot.figure.ax_merge(ax)[source]
Subplots
AxesmergeDimension parameters:
R = number of rows
C = number of columns
G = R * C
Example of 5x3 grid subplots
Subplot 1 ax1 (3x2)
Subplot 1 ax1 (3x2)
Subplot 4 ax4 (5x1)
Subplot 1 ax1 (3x2)
Subplot 1 ax1 (3x2)
Subplot 4 ax4 (5x1)
Subplot 1 ax1 (3x2)
Subplot 1 ax1 (3x2)
Subplot 4 ax4 (5x1)
Subplot 2 ax2 (2x1)
Subplot 3 ax3 (2x1)
Subplot 4 ax4 (5x1)
Subplot 2 ax2 (2x1)
Subplot 3 ax3 (2x1)
Subplot 4 ax4 (5x1)
>>> with plot_figure(None, 5, 3) as _ax: ... ax1 = ax_merge(_ax)[:3, :2] ... ax1.plot(np.arange(5), 'ro') ... ax1.set_title('subplot 1') ... ... ax2 = ax_merge(_ax)[3:, 1] ... ax2.imshow(np.random.sample((10, 10))) ... ax2.set_title('subplot 2') ... ... ax3 = ax_merge(_ax)[3:, 2] ... ax3.plot(np.arange(10), 'g*') ... ax3.set_title('subplot 3') ... ... D = np.random.normal((3, 5, 4), (0.75, 1.00, 0.75), (200, 3)) ... ax4 = ax_merge(_ax)[:, -1] ... ax4.violinplot(D, [2, 4, 6], widths=2, showmeans=False, showmedians=False, showextrema=False) ... ax4.set_title('subplot 4')
- Parameters:
ax (ndarray) – Array[Axes, G]
- Returns:
AxesMergeHelper- Return type:
AxesMergeHelper