larvaworld.lib.plot.base ======================== .. py:module:: larvaworld.lib.plot.base .. autoapi-nested-parse:: Basic plotting classes Classes ------- .. autoapisummary:: larvaworld.lib.plot.base.BasePlot larvaworld.lib.plot.base.AutoBasePlot larvaworld.lib.plot.base.AutoPlot larvaworld.lib.plot.base.GridPlot Module Contents --------------- .. py:class:: BasePlot(name: str = 'larvaworld_plot', save_as: Optional[str] = None, pref: Optional[str] = None, suf: str = 'pdf', save_to: Optional[str] = None, subfolder: Optional[str] = None, return_fig: bool = False, show: bool = False, subplot_kw: Dict[str, Any] = {}, build_kws: Dict[str, Any] = {}, **kwargs: Any) Base class for creating customizable matplotlib plots. Provides common functionality for plot generation, styling, and output management. Handles figure/axes creation, saving, and display options. Subclasses implement specific plot types by overriding plot methods. Attributes: filename: Output filename with extension fit_filename: Filename for fit data CSV save_to: Directory path for saving plots return_fig: Whether to return figure object show: Whether to display plot immediately build_kws: Keyword arguments for figure building Example: >>> plotter = BasePlot(name='myplot', save_to='./plots', suf='png') >>> plotter.build(nrows=2, ncols=2) >>> # ... add plot content ... >>> plotter.save() .. py:attribute:: filename :value: 'None.pdf' .. py:attribute:: fit_filename :value: 'None_fits.csv' .. py:attribute:: fit_ind :value: None .. py:attribute:: fit_df :value: None .. py:attribute:: save_to :value: None .. py:attribute:: return_fig :value: False .. py:attribute:: show :value: False .. py:attribute:: build_kws .. py:method:: build(fig: Optional[matplotlib.figure.Figure] = None, axs: Optional[Axes | Sequence[Axes]] = None, dim3: bool = False, azim: int = 115, elev: int = 15) -> None Method that defines the figure and axes on which to draw. These can be provided externally as arguments to create a composite figure. Otherwise they are created independently. Args: fig: The figure of the plot (optional) axs: The axes of the figure (optional) dim3: Whether the figure will be 3-dimensional. Default : False azim: The azimuth of a 3D figure. Default : 115 elev: The elevation of a 3D figure. Default : 15 .. py:property:: Naxs :type: int .. py:property:: Ncols :type: int .. py:property:: Nrows :type: int .. py:method:: conf_ax(idx: int = 0, ax: Optional[matplotlib.axes.Axes] = None, xlab: Optional[str] = None, ylab: Optional[str] = None, zlab: Optional[str] = None, xlim: Optional[Sequence[float]] = None, ylim: Optional[Sequence[float]] = None, zlim: Optional[Sequence[float]] = None, xticks: Optional[Sequence[float]] = None, xticklabels: Optional[Sequence[str]] = None, yticks: Optional[Sequence[float]] = None, xticklabelrotation: Optional[int] = None, yticklabelrotation: Optional[int] = None, yticklabels: Optional[Sequence[str]] = None, zticks: Optional[Sequence[float]] = None, zticklabels: Optional[Sequence[str]] = None, xtickpos: Optional[str] = None, xtickpad: Optional[int] = None, ytickpad: Optional[int] = None, ztickpad: Optional[int] = None, xlabelfontsize: Optional[int] = None, ylabelfontsize: Optional[int] = None, xticklabelsize: Optional[int] = None, yticklabelsize: Optional[int] = None, zticklabelsize: Optional[int] = None, major_ticklabelsize: Optional[int] = None, minor_ticklabelsize: Optional[int] = None, xlabelpad: Optional[int] = None, ylabelpad: Optional[int] = None, zlabelpad: Optional[int] = None, equal_aspect: Optional[bool] = None, xMaxN: Optional[int] = None, yMaxN: Optional[int] = None, zMaxN: Optional[int] = None, yStrN: Optional[int] = None, xMath: Optional[bool] = None, yMath: Optional[bool] = None, tickMath: Optional[Tuple[int, int]] = None, ytickMath: Optional[Tuple[int, int]] = None, xMaxFix: bool = False, leg_loc: Optional[str] = None, leg_handles: Optional[Sequence[Any]] = None, leg_labels: Optional[Sequence[str]] = None, legfontsize: Optional[int] = None, xvis: Optional[bool] = None, yvis: Optional[bool] = None, zvis: Optional[bool] = None, title: Optional[str] = None, title_y: Optional[float] = None, titlefontsize: Optional[int] = None) -> None Helper method that configures an axis of the figure .. py:method:: conf_ax_3d(vars: Sequence[str], target: str, lims: Optional[Tuple[Sequence[float], Sequence[float], Sequence[float]]] = None, title: Optional[str] = None, maxN: int = 3, labelpad: int = 15, tickpad: int = 5, idx: int = 0) -> None .. py:method:: adjust(LR: Optional[Tuple[float, float]] = None, BT: Optional[Tuple[float, float]] = None, W: Optional[float] = None, H: Optional[float] = None) -> None .. py:method:: set(fig: matplotlib.figure.Figure) -> None .. py:method:: get() -> Any .. py:method:: conf_fig(adjust_kws: Optional[Dict[str, Any]] = None, align: Optional[Sequence[matplotlib.axes.Axes] | Sequence[Any]] = None, title: Optional[str] = None, title_kws: Dict[str, Any] = {}) -> None .. py:class:: AutoBasePlot(fig: Optional[matplotlib.figure.Figure] = None, axs: Optional[Axes | Sequence[Axes]] = None, dim3: bool = False, azim: int = 115, elev: int = 15, **kwargs: Any) Bases: :py:obj:`BasePlot` Automatic plot generation with immediate figure building. Extends BasePlot by automatically calling build() during initialization, creating the matplotlib figure and axes immediately. Supports both 2D and 3D plots with customizable viewing angles. Attributes: fig: Matplotlib Figure object ax: Matplotlib Axes object (or array of Axes for subplots) dim3: Whether plot is 3D Example: >>> plot = AutoBasePlot(nrows=2, ncols=2, dim3=False) >>> plot.ax[0, 0].plot(x, y) # Use axes directly >>> plot.save() .. py:class:: AutoPlot(ks: Sequence[str] = [], key: str = 'step', klabels: Dict[str, str] = {}, datasets: Sequence[Any] = [], labels: Optional[Sequence[str]] = None, colors: Optional[Sequence[Any]] = None, add_samples: bool = False, ranges: Optional[Sequence[Any]] = None, absolute: bool = False, rad2deg: bool = False, space_unit: str = 'mm', **kwargs: Any) Bases: :py:obj:`AutoBasePlot`, :py:obj:`larvaworld.lib.process.LarvaDatasetCollection` Automatic plot generation with larvaworld dataset integration. Combines AutoBasePlot functionality with LarvaDatasetCollection to enable direct plotting from larvaworld LarvaDataset objects. Handles multiple datasets with automatic labeling, coloring, and unit conversion. Attributes: datasets: Collection of LarvaDataset objects labels: Dataset labels for legend colors: Colors for each dataset ks: Parameter keys to plot key: Indexing key ('step', 'time', etc.) klabels: Custom labels for parameters Ndatasets: Number of datasets Nks: Number of parameters Example: >>> plot = AutoPlot(datasets=[d1, d2], labels=['Control', 'Test']) >>> plot.plot(ks=['v', 'a']) # Plot velocity and acceleration >>> plot.save() .. py:attribute:: key :value: 'step' .. py:attribute:: ks :value: [] .. py:attribute:: kkdict .. py:attribute:: pdict .. py:attribute:: vdict .. py:attribute:: dkdict .. py:attribute:: pars .. py:attribute:: Nks :value: 0 .. py:attribute:: ranges :value: None .. py:attribute:: absolute :value: False .. py:attribute:: rad2deg :value: False .. py:method:: comp_all_pvalues() -> None .. py:method:: plot_all_half_circles() -> None .. py:method:: plot_half_circle(ax: matplotlib.axes.Axes, col1: Any, col2: Any, v: int, pv: float, coef: int = 0) -> bool .. py:method:: data_leg(idx: Optional[int] = None, labels: Optional[Sequence[str]] = None, colors: Optional[Sequence[Any]] = None, anchor: Optional[Tuple[float, float]] = None, handlelength: float = 0.5, handleheight: float = 0.5, Nagents_in_label: bool = True, **kwargs: Any) -> Any .. py:method:: plot_quantiles(k: Optional[str] = None, par: Optional[str] = None, idx: int = 0, ax: Optional[matplotlib.axes.Axes] = None, xlim: Optional[Sequence[float]] = None, ylim: Optional[Sequence[float]] = None, ylab: Optional[str] = None, unit: str = 'sec', leg_loc: str = 'upper left', coeff: float = 1, absolute: bool = False, individuals: bool = False, show_first: bool = False, Nagents_in_label: bool = True, **kwargs: Any) -> None .. py:method:: plot_hist(half_circles: bool = True, use_title: bool = False, par_legend: bool = False, nbins: int = 30, alpha: float = 0.5, ylim: Sequence[float] = [0, 0.2], Nagents_in_label: bool = True, **kwargs: Any) -> None .. py:method:: boxplots(grouped: bool = False, annotation: bool = True, show_ns: bool = False, target_only: Any = None, stripplot: bool = False, ylims: Optional[Sequence[Sequence[float]]] = None, **kwargs: Any) -> None .. py:class:: GridPlot(name: str, width: int, height: int, scale: Tuple[int, int] = (1, 1), **kwargs: Any) Bases: :py:obj:`BasePlot` Multi-panel grid layout for composite plots. Creates a grid-based figure layout using matplotlib GridSpec for organizing multiple subplots. Supports automatic subplot placement with optional lettering (A, B, C, ...) and flexible sizing. Attributes: width: Number of columns in grid height: Number of rows in grid fig: Matplotlib Figure object grid: GridSpec layout manager cur_w: Current column position cur_h: Current row position letters: List of panel labels letter_dict: Mapping of panel positions to letters Example: >>> grid = GridPlot(name='composite', width=3, height=2) >>> ax1 = grid.add() # Add first panel >>> ax2 = grid.add(N=2) # Add panel spanning 2 columns >>> grid.save() .. py:attribute:: fig .. py:attribute:: grid .. py:attribute:: cur_idx :value: 0 .. py:attribute:: letters :value: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'] .. py:attribute:: letter_dict .. py:method:: add(N: int = 1, w: Optional[int] = None, h: Optional[int] = None, w0: Optional[int] = None, h0: Optional[int] = None, dw: int = 0, dh: int = 0, share_w: bool = False, share_h: bool = False, letter: bool = True, x0: bool = False, y0: bool = False, cols_first: bool = False, annotate_all: bool = False) -> Axes | list[Axes] .. py:method:: add_letter(ax: matplotlib.axes.Axes, letter: bool = True, x0: bool = False, y0: bool = False) -> None .. py:method:: annotate(dx: float = -0.05, dy: float = 0.005, full_dict: bool = False) -> None .. py:method:: plot(func: str, kws: Dict[str, Any], axs: Optional[Sequence[matplotlib.axes.Axes]] = None, **kwargs: Any) -> Any