GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Count plot in seaborn

Search for a graph

HOME RANKING COUNTPLOT SEABORN

Count plot in seaborn

Count plot in seaborn with countplot

The countplot function can be used to represent the number of observations of a categorical variable for each group with bars.

import seaborn as sns

data = ["A", "A", "B",
        "B", "B", "C"]

# Count plot
sns.countplot(x = data)

Count plot in Python with the countplot function

Horizontal count plot

In case you want to create a horizontal count plot you will need to pass your data to the y argument, instead of x.

import seaborn as sns

data = ["A", "A", "B",
        "B", "B", "C"]

# Count plot
sns.countplot(y = data)

Horizontal count plot in seaborn

Count plot by group and subgroup

Dodged count plot in seaborn

Dodged count plot

In addition, if you have another categorical variable representing subgroups you can input it to the hue argument, as shown below. Set dodge = False in case you want to overplot the bars for each group.

import seaborn as sns

data = ["A", "A", "B", "A",
        "B", "B", "C", "C"]
group = ["G1", "G1", "G2", "G2",
         "G1", "G2", "G1", "G2"]

# Count plot
sns.countplot(x = data, hue = group)

Color customization

Color saturation

The saturation of the colors of the bars is 0.75 by default. However, you can make use of the saturation argument to change it, being 0 desaturated and 1 fully saturated.

import seaborn as sns

data = ["A", "A", "B",
        "B", "B", "C"]

# Count plot
sns.countplot(x = data, saturation = 1)

seaborn bar color saturation

Color palette

If you want to override the default color palette you can change it with the palette argument, as in the example below.

import seaborn as sns

data = ["A", "A", "B",
        "B", "B", "C"]

# Count plot
sns.countplot(x = data, palette = "Set1")

Change the color palette of the Python count plot

Same color for all the bars

You can also set the same color for all the bars passing a named color to the color argument of the function.

import seaborn as sns

data = ["A", "A", "B",
        "B", "B", "C"]

# Count plot
sns.countplot(x = data,
              color = "lightblue")

Same color for all the bars in seaborn

Border color

Finally, you can also modify the colors of the borders for each bar, setting a color or a vector of colors with edgecolor.

import seaborn as sns

data = ["A", "A", "B",
        "B", "B", "C"]

# Count plot
sns.countplot(x = data,
              edgecolor = "black")

Border color of a count plot in seaborn

R CODER website
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon
Data visualization

Data visualization

A practical introduction

Buy on Amazon

See also

Wordclouds in Python

Wordclouds in Python

Bar plot in matplotlib

Bar plot in matplotlib

Population pyramid in matplotlib

Population pyramid in matplotlib

Radar chart in matplotlib

Radar chart in matplotlib

Tables in matplotlib

Tables in matplotlib

Stem plot (lollipop chart) in matplotlib

Stem plot (lollipop chart) in matplotlib

Circular barplot in matplotlib

Circular barplot in matplotlib

Bar chart in pandas

Bar chart in pandas

Bar plot in seaborn

Bar plot in seaborn

Bar chart in plotly

Bar chart in plotly

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.