scallops.visualize.heatmap.plot_well_aggregated_heatmaps

scallops.visualize.heatmap.plot_well_aggregated_heatmaps(df, agg_function, feature, grid_size=40, plate_shape=(2, 3), tile_size_x=2720, tile_size_y=2720, xlabel={'Minimum number of spots per cell:': <function nanmin>}, cbar_label='Number of spots', x_col_name='x', y_col_name='y')

Generates aggregated heatmap plots for each well in the dataset using a specified aggregation function.

This function creates a figure containing heatmaps for six wells based on the provided DataFrame. Each heatmap represents the spatial distribution of a computed metric over a grid, calculated using the supplied aggregation function.

Parameters:
  • df (DataFrame) – Input DataFrame containing data for all wells. Must contain ‘well’, ‘x’, and ‘y’ columns.

  • agg_function (callable) – Aggregation function to apply to each group of data in the grid (e.g., np.mean, np.sum). The function should accept a DataFrame and return a scalar value.

  • feature (str) – feature to plot. Must exist in dataframe as column

  • grid_size (int) – Size of the grid (number of bins along x and y axes). Default is 40.

  • plate_shape (tuple[int, int]) – Tuple with row,column shape of the plate

  • tile_size_x (float) – Size of the tile along the x-axis, used to bin the x coordinates. Default is 2720.

  • tile_size_y (float) – Size of the tile along the y-axis, used to bin the y coordinates. Default is 2720.

  • xlabel (dict) – Dictionary with label as key and a function to compute a value from the heatmap. Default is {‘Minimum number of spots per cell:’: np.nanmin}.

  • cbar_label (str) – Label for the colorbar in the heatmaps. Default is ‘Number of spots’.

  • x_col_name – Column where the x coordinates reside.

  • y_col_name – Column where the y coordinates reside.

Returns:

Matplotlib Figure object containing the heatmaps.

Example:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Example DataFrame
df = pd.DataFrame(
    {
        "well": np.random.randint(1, 7, size=1000),
        "x": np.random.rand(1000) * 10000,
        "y": np.random.rand(1000) * 10000,
        "value": np.random.rand(1000),
    }
)


# Function to aggregate values
def mean_value(group):
    return group["value"].mean()


# Generate heatmaps
fig = plot_well_aggregated_heatmaps(df, mean_value)

# Display the figure
plt.show()
Return type:

Figure