Seaborn sns.stripplot Example

import pandas as pd
from IPython.display import display

import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set_style('darkgrid')

# load_data
iris = pd.melt(sns.load_dataset('iris'), "species", var_name="measurement")
display(iris.head())
species measurement value
0 setosa sepal_length 5.1
1 setosa sepal_length 4.9
2 setosa sepal_length 4.7
3 setosa sepal_length 4.6
4 setosa sepal_length 5.0

Basic Cat vs Num

sns.stripplot(x="measurement", y="value", data=iris)
plt.show()

## Visualize three variables with * hue = *

e.g. cat vs. num vs. cat

sns.stripplot(x="measurement", y="value", hue="species", data=iris) 
plt.show()

Visualize three variables with hue = * and dodge = *

sns.stripplot(x="measurement", y="value", hue="species", data=iris, dodge = True)
plt.show()

Introduce variance to Categorical features with jitter =

sns.stripplot(x="measurement", y="value", hue="species", data=iris, dodge = True, jitter= 0.2)
plt.show()

Better separation of individual data with *edgecolor = *

sns.stripplot(x="measurement", y="value", hue="species", data=iris, jitter=0.2, split = True, linewidth=0.5, edgecolor = "white")
plt.show()

Change color palette with * palette = *

sns.stripplot(x="measurement", y="value", hue="species", data=iris, 
              jitter=True, dodge = True, linewidth=0.5, edgecolor = "white", palette = 'Set2')
plt.show()

Reference:

  • https://seaborn.pydata.org/generated/seaborn.stripplot.html