neuralib.plot.figure.plot_figure

neuralib.plot.figure.plot_figure(output, *args, set_square=False, set_equal_scale=False, win_backend=None, 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 (str | Path | PathLike[str] | 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:

Iterator[Axes | ndarray]