camfi.plotting.matplotlib module

class camfi.plotting.matplotlib.MatplotlibWingbeatFrequencyPlotter(*, polyline_regions: pandas.core.frame.DataFrame, snr_thresh: float = 4.0, class_mask: numpy.ndarray = None, gmm_results: list = None, bces_results: list = None, figsize: tuple = (7.5, 5.2), left_border: float = 0.1, bottom_border: float = 0.1, snr_vs_pwf_ax_width: float = 0.4, snr_vs_pwf_ax_height: float = 0.4, hist_height: float = 0.2, l_vs_pdt_spacing: float = - 0.12, snr_vs_pwf_alpha: float = 1.0, snr_vs_pwf_abovethresh_c: str = 'k', snr_vs_pwf_belowthresh_c: str = 'grey', snr_thresh_line_c: str = 'r', errorbar_lw: float = 1, gmm_plot_range_stdevs: float = 4.0, gmm_lw: float = 3, l_vs_pdt_alpha: float = 0.5, class_colours: list = ['tab:blue', 'tab:green', 'tab:orange', 'tab:red', 'tab:purple', 'k'], snr_vs_pwf_title: str = ' (a)', snr_vs_pwf_title_y: float = 0.87, l_vs_pdt_title: str = ' (b)', l_vs_pdt_title_y: float = 0.91, title_font_dict: dict = {'fontweight': 'bold'}, fig: matplotlib.figure.Figure = None, snr_vs_pwf_ax: matplotlib.axes._axes.Axes = None, histx_ax: matplotlib.axes._axes.Axes = None, histy_ax: matplotlib.axes._axes.Axes = None, l_vs_pdt_ax: matplotlib.axes._axes.Axes = None, above_thresh: pandas.core.frame.DataFrame = None, below_thresh: pandas.core.frame.DataFrame = None)

Bases: pydantic.main.BaseModel

Produces plots of wingbeat frequency measurements. Most parameters are just to control exactly how the plot looks, and the defaults should make it look pretty. Probably only need to set polyline_regions, snr_thresh, class_mask, gmm_results, and bces_results parameters, but everything else is exposed for fine control.

A few fields come up in the class signature, but should not be set manually. These are ommitted from the parameter list.

Parameters
  • polyline_regions (pd.DataFrame) – Dataframe containing wingbeat data. Each entry should be a polyline region with all columns filled. (See camfi.datamodel.via.ViaProject.to_region_dataframe for dataframe creation).

  • snr_thresh (float) – SNR threshold to plot.

  • class_mask (Optional[np.ndarray]) – Array of class indices. Should have same length as the thresholded dataset, obtained by calling polyline_regions[polyline_regions[“snr”] >= snr_thresh.

  • gmm_results (Optional[list[WeightedGaussian]]) – If provided, a log10 Gaussian mixture model will be plotted on the horizontal marginal distribution histogram of the snr_vs_pwf plot. See camfi.wingbeat.GMM for creating this list.

  • bces_results (Optional[list[BcesResult]]) – If provided, BCES regression lines will be plotted on the l_vs_pdt plot. See camfi.wingbeat.BcesEM for creating this list.

  • figsize (tuple[float, float]) – Size (width, height) of figure in inches (shudders …This is the units matplotlib uses).

  • left_border (float) – Proportion of figure width to pad on left side.

  • bottom_border (float) – Proportion of figure height to pad on bottom side.

  • snr_vs_pwf_ax_width (float) – Width of snr_vs_pwf plot as a proportion of total figure width.

  • snr_vs_pwf_ax_height (float) – Height of snr_vs_pwf plot as a proportion of total figure height.

  • hist_height (float) – Height of snr_vs_pwf marginal histograms as a proportion of total figure height and width.

  • l_vs_pdt_spacing (float) – Horizontal spacing between l_vs_pdt plot and snr_vs_pwf plot. Negative values indicate that plots should overlap.

  • snr_vs_pwf_alpha (float) – Alpha level (opacity) to apply to error bars and histograms for snr_vs_pwf plot.

  • snr_vs_pwf_abovethresh_c (str) – Colour for above-threshold error bars on snr_vs_pwf plot.

  • snr_vs_pwf_belowthresh_c (str) – Colour for below-threshold error bars on snr_vs_pwf plot.

  • snr_thresh_line_c (str) – Colour of SNR threshold line.

  • errorbar_lw (float) – Line width of error bars. Applied across both subfigures.

  • gmm_plot_range_stdevs (float) – Number of standard deviations either side of means to plot for GMM pdfs.

  • gmm_lw (float) – Line width for GMM pdfs. By default this is bold for easier viewing.

  • l_vs_pdt_alpha (float) – Alpha level (opacity) to apply to error bars for l_vs_pdt plot.

  • class_colours (list[str]) – list of colours to use for plotting multiple classes (both for GMM and BCES, and class_mask). This will apply the colours to the classes in the order they are given. If class_mask is not supplied, the last colour in the list is used for all datapoints.

  • snr_vs_pwf_title (str) – Title for snr_vs_pwf plot.

  • snr_vs_pwf_title_y (float = 0.87) – Vertical position of title for snr_vs_pwf plot.

  • l_vs_pdt_title (str = " (b)") – Title for l_vs_pdt plot.

  • l_vs_pdt_title_y (float = 0.91) – Vertical position of title for l_vs_pdt plot.

  • title_font_dict (dict[str, Any] = {"fontweight" : "bold"}) – Defines font parameters for subfig titles.

plot() matplotlib.figure.Figure

Produces plots.

class camfi.plotting.matplotlib.MatplotlibWingbeatSuppFigPlotter(*, root: pathlib.Path, image_filename: pathlib.Path, suffix: str = '.png', annotation_idx: pydantic.types.NonNegativeInt = 0)

Bases: camfi.wingbeat.WingbeatSuppFigPlotter

Implementation of WingbeatSuppFigPlotter using matplotlib.

__call__(region_attributes: camfi.datamodel.via_region_attributes.ViaRegionAttributes, region_of_interest: torch.Tensor, mean_autocorrelation: torch.Tensor) None

Plot a supplementary figure of wingbeat extraction, saving the image to a file.

Parameters
  • region_attributes (ViaRegionAttributes) – With fields calculated (e.g. by WingbeatExtractor.process_blur).

  • region_of_interest (Tensor) – Greyscale image Tensor displaying region of interest.

  • mean_autocorrelation (Tensor) – 1-d Tensor with values containing autocorrrelation along axis 1 of region_of_interest.

camfi.plotting.matplotlib.plot_activity_levels_summaries(df: pandas.core.frame.DataFrame, locations: list, sub_figsize: tuple = (9, 5), ax_kwargs: dict = {}, separate_plots: bool = True, **kwargs) matplotlib.figure.Figure

Calls plot_activity_levels_summary for multiple locations, to produce multiple histogram plots of activity levels.

Parameters
  • df (pd.DataFrame) – DataFrame which must contain columns “n_annotations”, and be indexed by location in locations.

  • locations (list[str]) – list of locations to plot data for. [df.loc[location] for location in locations] should be valid.

  • sub_figsize (tuple[float, float]) – Figure size (in inches). If separate_plots is True, then each subfigure will be this size.

  • ax_kwargs (dict) – Keyword arguments passed to plt.Figure.add_subplot.

  • separate_plots (bool) – If True (default), each plot will be put on a separate subfigure. If False, they will all be plotted on the same axes.

  • **kwargs – Passed to plot_activity_levels_summary.

Returns

fig – Figure containing plots.

Return type

plt.Figure

camfi.plotting.matplotlib.plot_activity_levels_summary(df: pandas.core.frame.DataFrame, ax: matplotlib.axes._axes.Axes, x_column: str = 'daynumber', bin_width: float = 0.006944444444444444, **kwargs) list

Produces a histogram plot of df[“n_annotations”] vs. df[x_column].

Parameters
  • df (pd.DataFrame) – DataFrame which must contain columns “n_annotations” and x_column.

  • ax (plt.Axes) – Matplotlib axes to plot histogram on.

  • x_column (str) – Column of df to use as x-axis data.

  • bin_width (float) – Width of histogram bins, in same units as x_column.

  • **kwargs – Passed to plt.Axes.plot.

Returns

lines – list of plot lines.

Return type

list[plt.Line2D]

camfi.plotting.matplotlib.plot_daily_temperatures(df: pandas.core.frame.DataFrame, ax: matplotlib.axes._axes.Axes, minimum_col: str = 'temperature_minimum_evening_degC', **kwargs) list

Plots daily temperature values on ax.

Parameters
  • df (pd.DataFrame) – DataFrame with columns “daynumber”, “temperature_maximum_degC”, “temperature_3pm_degC”, “temperature_9am_degC”, and minimum_col.

  • ax (plt.Axes) – Axes to put plots on.

  • minimum_col (str) – Name of column for minimum daily temperature. E.g. “temperature_minimum_degC”, or “temperature_minimum_evening_degC” (default).

  • **kwargs – Passed to each call to ax.plot.

Returns

lines – list of plot lines.

Return type

list[plt.Line2D]

camfi.plotting.matplotlib.plot_herror_bars(axes: matplotlib.axes._axes.Axes, lower: numpy.ndarray, upper: numpy.ndarray, y: numpy.ndarray, **kwargs) list

Plots horizontal error bars on a set of axes.

Parameters
  • axes (plt.Axes) – Axes to plot error bars on.

  • lower (np.ndarray) – Lower x-values of error bars.

  • upper (np.ndarray) – Upper x-values of error bars. Should have same shape as lower.

  • y (np.ndarray) – y-values. Should have same shape as upper and lower.

  • **kwargs (dict) – Passed to plt.plot.

camfi.plotting.matplotlib.plot_maelstroms(df: pandas.core.frame.DataFrame, ax: matplotlib.axes._axes.Axes, **kwargs) list

Plots “n_annotations” vs “daynumber”, with data taken from df.

Parameters
  • df (pd.DataFrame) – DataFrame with columns “daynumber” and “n_annotations”.

  • ax (plt.Axes) – Axes to plot onto.

  • **kwargs – Passed to ax.plot.

camfi.plotting.matplotlib.plot_maelstroms_with_temperature(df: pandas.core.frame.DataFrame, ax: matplotlib.axes._axes.Axes, maelstrom_kwargs: dict = {}, temperatures_kwargs: dict = {}) tuple

Calls plot_maelstrom, then makes a twinx axes from ax, and calls plot_daily_temperatures.

Parameters
  • df (DataFrame) – Passed to plot_maelstrom and plot_daily_temperatures.

  • ax (plt.Axes) – Axes to plot maelstrom data onto. Temperature data is put on a new Axes created by calling ax.twinx().

  • maelstrom_kwargs (dict) – Keyword arguments passed to plot_maelstrom.

  • temperatures_kwargs (dict) – Keyword arguments passed to plot_daily_temperatures.

Returns

  • maelstrom_lines (list[plt.Line2D]) – Maelstrom plot lines.

  • temperature_lines (list[plt.Line2D]) – Temperature plot lines.