voyagerpy.plotting.plot_bin2d#
- voyagerpy.plotting.plot_bin2d(data: AnnData | DataFrame, x: str, y: str, filt: str | None = None, subset: str | None = None, bins: int = 101, name_true: str | None = None, name_false: str | None = None, hex_plot: bool = False, cmap: str | None = 'Blues7', cmap_true: str | None = 'Reds', binwidth: float | None = None, ax: Axes | None = None, **plot_kwargs) Axes#
Plot a 2D histogram of two features.
If hex_plot is True, a hexbin plot is used instead of an ordinary 2D histogram.
To split the data by a third feature, pass the name of the column to subset. This subset will be evaluated as a boolean mask, and the data will be split into two histograms in the same axes, one for each truth value in subset.
To filter the data by a third feature, pass the name of the column to filt. This filter will be evaluated as a boolean mask, and the data will be filtered before plotting. This is useful for removing outliers from the plot.
- Parameters:
data (Union[AnnData, DataFrame]) – AnnData or DataFrame containing the data to plot. If an AnnData is passed, the obs dataframe is used.
x (str) – The name of the column in data to use as the x-axis.
y (str) – The name of the column in data to use as the y-axis.
filt (Optional[str], optional) – The name of the column in data to filter by, by default None. This argument can also be bool array-like.
subset (Optional[str], optional) – The name of the column in data to subset by, by default None. If None, all data is used. Otherwise, two histograms are overlain, one for each truth value in subset. This argument can also be bool array-like.
bins (int, optional) – The number of bins to use along both axes of the plot, by default 101.
name_true (Optional[str], optional) – The colorbar title for when subset is True, by default None.
name_false (Optional[str], optional) – The colorbar title for when subset is False, by default None.
hex_plot (bool, optional) – Create hexagonal bins, by default False.
cmap (Optional[str], optional) – The colormap to use for the histogram, by default “Blues7”.
cmap_true (Optional[str], optional) – The colormap to use for the histogram for when subset is False, by default “Reds”.
binwidth (Optional[float], optional) – The width of the bins, by default None.
ax (Optional[Axes], optional) – The axis to use, by default None.
**plot_kwargs –
Additional keyword arguments to pass to the corresponding plotting function. Additionally, the following keys are supported:
x_label: The label for the x-axis.
y_label: The label for the y-axis.
figsize: The size of the figure if ax is None.
- Returns:
The axis containing the plot.
- Return type:
Axes
Notes
If hex_plot is True, this function renames some of the keyword arguments to match the names used by matplotlib.pyplot.hexbin. The following renames are performed:
bins -> gridsize
cmin -> mincnt