scanpex.sns package
- scanpex.sns.catlollipop(data, x=None, y=None, hue=None, palette=None, ax=None, **kwargs)[source]
Draw a categorical lollipop plot with dodging capabilities.
This function creates a lollipop plot (a variation of a bar plot consisting of a segment and a dot) for categorical data. It automatically detects the orientation based on the numeric data type of x or y. It also supports grouping by a hue variable, which “dodges” (offsets) the lollipops to avoid overlap.
- Parameters:
data (pd.DataFrame) – Input data structure.
x (str, optional) – Variables that specify positions on the x and y axes. One should be categorical and the other numeric. The function determines orientation automatically.
y (str, optional) – Variables that specify positions on the x and y axes. One should be categorical and the other numeric. The function determines orientation automatically.
hue (str, optional) – Grouping variable that will produce points with different colors. Also used to offset (dodge) the stems for better visibility.
palette (str, list, dict, or matplotlib.colors.Colormap, optional) – Method for choosing the colors to use when mapping the hue semantic. If None, defaults to “tab10”.
ax (matplotlib.axes.Axes, optional) – Pre-existing axes for the plot. Otherwise, a new figure and axes are created.
**kwargs – Other keyword arguments are passed through to seaborn.scatterplot.
- Returns:
The Axes object with the plot drawn onto it.
- Return type:
matplotlib.axes.Axes
- scanpex.sns.lollipop(data, x=None, y=None, hue=None, lim=None, palette=None, ax=None, **kwargs)[source]
Draw a lollipop plot with stems and markers, supporting hue and custom limits.
This function plots a stem (line) for each data row, extending from a baseline to the data point. It automatically detects the orientation based on which axis is numeric. It integrates with seaborn.scatterplot for marker rendering, allowing for hue grouping and other aesthetic customizations.
- Parameters:
data (pd.DataFrame) – Input data structure.
x (str, optional) – Column name for the x-axis. If numeric, a horizontal lollipop plot is drawn using the row index as the y-position.
y (str, optional) – Column name for the y-axis. If numeric (and x is not), a vertical lollipop plot is drawn using the row index as the x-position.
hue (str, optional) – Grouping variable passed to seaborn.scatterplot. Note: Stems are colored individually by row index using palette. If hue is used, ensure palette is compatible or accept that stems and markers may follow different coloring logics.
lim (list of float, optional) – Custom limits [min, max] for the numeric axis. The minimum value (lim[0]) is used as the baseline for the stems. If None, the current axis limits are used.
palette (list or seaborn palette, optional) – Colors to use for the stems. If None, generates a ‘husl’ palette with a distinct color for each row.
ax (matplotlib.axes.Axes, optional) – Pre-existing axes for the plot. Otherwise, a new figure and axes are created.
**kwargs – Other keyword arguments are passed through to seaborn.scatterplot.
- Returns:
The Axes object with the plot drawn onto it.
- Return type:
matplotlib.axes.Axes
- scanpex.sns.vinswarm(data, x=None, y=None, hue=None, inner=None, cut=0, alpha=0.5, s=1, jitter=0.4, zorder=0, ax=None, **kwargs)[source]
Overlay a strip plot on a violin plot to visualize distribution and raw points.
This function combines seaborn.violinplot (showing the kernel density estimate) and seaborn.stripplot (showing individual data points). It allows for simultaneous visualization of the underlying distribution shape and the sample density/outliers.
- Parameters:
data (pd.DataFrame) – Input data structure.
x (str, optional) – Variables that specify positions on the x and y axes.
y (str, optional) – Variables that specify positions on the x and y axes.
hue (str, optional) – Grouping variable that will produce elements with different colors.
inner (str or None, optional) – Representation of the datapoints in the violin interior. Defaults to None (to avoid cluttering with the strip plot).
cut (float, default 0) – Distance to extend the density past the extreme datapoints. Set to 0 to limit the violin range strictly within the data range.
alpha (float, default 0.5) – Proportional opacity of the violin plot fill.
s (float, default 1) – Size of the markers in the strip plot.
jitter (float or bool, default 0.4) – Amount of jitter (only along the categorical axis) to apply to the strip plot points.
zorder (int, default 0) – The z-order for the strip plot points. Higher values draw points on top of the violin.
ax (matplotlib.axes.Axes, optional) – Pre-existing axes for the plot. Otherwise, a new figure and axes are created.
**kwargs – Other keyword arguments are passed to both seaborn.violinplot and seaborn.stripplot.
- Returns:
The Axes object with the plot drawn onto it.
- Return type:
matplotlib.axes.Axes