• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How To Make Stripplot using Seaborn Catplot?

datavizpyr · March 20, 2020 ·

Stripplots are like scatter plots but one of the variables is a categorical variable. Stripplots are a great addition to boxplots as it shows complete data on the plot. Stripplots are more useful when can add random noise called “jitter” to avoid overlapping of data points with same values. In this post, we will learn how to make stripplot with jitter using Seaborn’s Catplot function.

Let us first load Seaborn and other python libraries useful for making stripplots.

import seaborn as sns 
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

We will generate data to make stripplot with jitter using Seaborn’s Catplot function. We use NumPy’s random module to simulate data for making the stripplot.

np.random.seed(42)
# Generating Data
df = pd.DataFrame({
    'Morocco': np.random.normal(57, 5,100),
    'USA': np.random.normal(73, 5, 100),
    'Jamaica': np.random.normal(68, 8,100),
    'Sierra Leone': np.random.normal(37, 10, 100),
    'Iceland': np.random.normal(76, 5, 100)
  })

Our data looks like this. It is in wide form with multiple countries’ life expectancy in each column.

print(df.head())
     Morocco        USA    Jamaica  Sierra Leone    Iceland
0  59.483571  65.923146  70.862299     28.710050  68.027862
1  56.308678  70.896773  72.486276     31.398190  73.003125
2  60.238443  71.286427  76.664410     44.472936  76.026218
3  64.615149  68.988614  76.430416     43.103703  76.234903
4  55.829233  72.193571  56.978645     36.790984  73.749673

Stripplot with Seaborn Catplot using Data in Wide form

Seaborn’s Catplot function is versatile in making plots involving categorical variables. For example, Catplot can take in data in wide form and make stripplot. To make stripplot with jitter using Catplot, we simply provide the data in wiode form with kind=”strip” argument.

sns.catplot(data=df, kind="strip");
plt.xlabel("Country",size=14)
plt.ylabel("LifeExp",size=14)
plt.savefig("Stripplot_using_Seaborn_Catplot_with_wide_data_Python.png")

And we get a nice stripplot with jitter automatically coloring different groups.

Stripplot using Seaborn Catplot with wide data
Stripplot using Seaborn Catplot with wide data

Stripplot with Seaborn Catplot using Data in tidy/long form

Often, working with data in tidy for is lot easier and here we will see an example of making stripplot with data in tidy long form

Our data in this example is in wide form. Let us first convert the data to tidy long form using Pandas’s melt function.

df_long = pd.melt(df, var_name="country", value_name="lifeExp")
df_long.head()

Our data in tidy long form contains two variables; conutry and lifeExp

df_long.head()
country	lifeExp
0	Morocco	59.483571
1	Morocco	56.308678
2	Morocco	60.238443
3	Morocco	64.615149
4	Morocco	55.829233

With the tidy data, we can use Seaborn’s catplot function to make stripplot with jitter. Now, we need to specify the two variables for x and y-axis with kind=”strip”.

sns.catplot(data=df_long, x= 'country', y='lifeExp', kind="strip")
plt.xlabel("Country",size=14)
plt.ylabel("LifeExp",size=14)
plt.savefig("Stripplot_using_Seaborn_Catplot_with_long_data_Python.png")

We get stripplot that looks the same as the one we made with data in wide form using Seaborn’s catplot.

Stripplot using Seaborn Catplot with long data
Stripplot using Seaborn Catplot with long data

Related posts:

Grouped Boxplot in Python with SeabornGrouped Boxplots in Python with Seaborn Grouped Barplot with SeabornHow To Make Grouped Barplots in Python with Seaborn? Horizontal Stripplot with Jitter in AltairHorizontal Stripplot with Jitter using Altair in Python Grouped Boxplot with Jittered Data Points SeabornGrouped Boxplot with Jittered Points with Seaborn Python

Filed Under: Python, Stripplot Seaborn Catplot Tagged With: Python, Seaborn, Stripplot

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version