shap.plots.beeswarm

shap.plots.beeswarm(shap_values: Explanation, max_display: int | None = 10, order=shap.Explanation.abs.mean(0), clustering=None, cluster_threshold=0.5, color=None, axis_color='#333333', alpha: float = 1.0, ax: Axes | None = None, show: bool = True, log_scale: bool = False, color_bar: bool = True, s: float = 16, plot_size: Literal['auto'] | float | tuple[float, float] | None = 'auto', color_bar_label: str = 'Feature value', group_remaining_features: bool = True)

Create a SHAP beeswarm plot, colored by feature values when they are provided.

Parameters:
shap_valuesExplanation

This is an Explanation object containing a matrix of SHAP values (# samples x # features).

max_displayint

How many top features to include in the plot (default is 10, or 7 for interaction plots).

ax: matplotlib Axes

Axes object to draw the plot onto, otherwise uses the current Axes.

showbool

Whether matplotlib.pyplot.show() is called before returning. Setting this to False allows the plot to be customized further after it has been created, returning the current axis via matplotlib.pyplot.gca().

color_barbool

Whether to draw the color bar (legend).

sfloat

What size to make the markers. For further information, see s in matplotlib.pyplot.scatter().

plot_size“auto” (default), float, (float, float), or None

What size to make the plot. By default, the size is auto-scaled based on the number of features that are being displayed. Passing a single float will cause each row to be that many inches high. Passing a pair of floats will scale the plot by that number of inches. If None is passed, then the size of the current figure will be left unchanged. If ax is not None, then passing plot_size will raise a ValueError.

group_remaining_features: bool

If there are more features than max_display, then plot a row representing the sum of SHAP values of all remaining features. Default True.

Returns:
ax: matplotlib Axes

Returns the Axes object with the plot drawn onto it. Only returned if show=False.

Examples

See beeswarm plot examples.