scallops.visualize.distribution.ridge_plot
- scallops.visualize.distribution.ridge_plot(data, feature, row, col=None, scale=None, aspect=5, height=10, title=None, palette='Spectral', **kwargs)
Create a ridge plot to visualize the distribution of a numeric variable across different categorical groups.
The ridge plot is particularly useful for displaying the distribution of a numeric variable (e.g., gene expression) across different categories, such as experimental groups or conditions. It uses kernel density estimation to provide a smooth representation of the data.
- Parameters:
data (DataFrame) – A pandas DataFrame containing the feature to plot.
feature (str) – The numeric variable in the image to be drawn on separate facets grouped by row and col features.
row (str) – The categorical variable in the image to group the feature by and be drawn on separate row facets in the grid.
col (str | None) – The categorical variable in the image to group the feature by and be drawn on separate column facets in the grid.
scale (str | None) – Whether to scale row. Options are None (no scaling), “standard” (subtract the mean and divide by standard deviation), or “log” for log10 scaling.
height (int | None) – The height (in inches) of each facet. See also: aspect.
aspect (int | None) – The aspect ratio of each facet, so that aspect * height gives the width of each facet in inches.
palette (str | None) – The colors to use for the different levels of the hue variable. Should be something that can be interpreted by seaborn’s color_palette().
title (str | None) – An optional string to set as the title of the figure.
kwargs (dict) – Optional mapping of arguments to be passed to FacetGrid
- Returns:
A seaborn FacetGrid containing the ridge plot.
- Example:
import pandas as pd import seaborn as sns import numpy as np import matplotlib.pyplot as plt from scallops.visualize import ridge_plot # Create a sample DataFrame np.random.seed(42) data = pd.DataFrame( { "category": np.random.choice(["A", "B", "C"], size=300), "group": np.random.choice(["X", "Y"], size=300), "value": np.random.normal(size=300), } ) # Generate a ridge plot ridge_plot( data=data, feature="value", row="category", col="group", scale="standard", title="Ridge Plot Example", ) # Show the plot plt.show()
- Return type:
FacetGrid
Note
This function uses seaborn’s FacetGrid to create a ridge plot, where the density of a numeric variable is displayed across different categorical groups.
The scale parameter allows you to scale the row variable for better visualization.
The palette parameter determines the color palette to use for different levels of the hue variable.