seaborn.countplot
- seaborn.countplot(data=None, *, x=None, y=None, hue=None, order=None, hue_order=None, orient=None, color=None, palette=None, , , , , , , , , , , , ,
Show the counts of observations in each categorical bin using bars.
A count plot can be thought of as a histogram across a categorical, instead
of quantitative, variable. The basic API and options are identical to those
for barplot(), so you can compare counts across nested variables.
Note that histplot() function offers similar functionality with additional
features (e.g. bar stacking), although its default behavior is somewhat different.
See the tutorial for more information.
Dataset for plotting. If x and y are absent, this is
interpreted as wide-form. Otherwise it is expected to be long-form.
data or vector dataInputs for plotting long-form data. See examples for interpretation.
Order to plot the categorical levels in; otherwise the levels are inferred from the data objects.
Orientation of the plot (vertical or horizontal). This is usually
inferred based on the type of the input variables, but it can be used
to resolve ambiguity when both x and are numeric or when
plotting wide-form data.
Returns the Axes object with the plot drawn onto it.
Show the count of value for a single categorical variable:
sns.countplot(titanic, x="class")
Group by a second variable:
sns.countplot(titanic, x="class", hue="survived")
Normalize the counts to show percentages:
sns.countplot(titanic, x="class", hue="survived", stat="percent")
Single color for the elements in the plot.
Colors to use for the different levels of the hue variable. Should
be something that can be interpreted by color_palette(), or a
dictionary mapping hue levels to matplotlib colors.
Proportion of the original saturation to draw fill colors in. Large
patches often look better with desaturated colors, but set this to
1 if you want the colors to perfectly match the input values.
matplotlib.colors.Normalize objectNormalization in data units for colormap applied to the hue
variable when it is numeric. Not relevant if hue is categorical.
Statistic to compute; when not 'count', bar heights will be normalized so that
they sum to 100 (for 'percent') or 1 (otherwise) across the plot.
Width allotted to each element on the orient axis. When native_scale=True,
it is relative to the minimum distance between two values in the native scale.
When hue mapping is used, whether elements should be narrowed and shifted along
the orient axis to eliminate overlap. If "auto", set to True when the
orient variable is crossed with the categorical variable or False otherwise.
Set axis scale(s) to log. A single value sets the data axis for any numeric
axes in the plot. A pair of values sets each axis independently.
Numeric values are interpreted as the desired base (default 10).
When None or False, seaborn defers to the existing Axes scale.
When True, numeric or datetime values on the categorical axis will maintain their original scaling rather than being converted to fixed indices.
Function for converting categorical data into strings. Affects both grouping and tick labels.
How to draw the legend. If “brief”, numeric hue and size
variables will be represented with a sample of evenly spaced values.
If “full”, every group will get an entry in the legend. If “auto”,
choose between brief or full representation based on number of levels.
If False, no legend data is added and no legend is drawn.
Axes object to draw the plot onto, otherwise uses the current Axes.
Other parameters are passed through to matplotlib.patches.Rectangle.