Visualize sample size in multiple Seaborn Stripplot

Viewed 398

I'm trying to visualize multiple data distributions using Seaborn stripplot. This plot gives some insights about the sample size. But when the distributions are similar, it is hard to compare the sample size. For example, in the figure below, stage 7 and 10 have very similar distributions, but stage 7 has 5990 values, and stage 10 has 32320. I tried different alpha values to get darker regions with more data samples, but it doesn't work very well. Any idea to distinguish sample size in multiple distributions using stripplot or any other visualization alternative?

Thank you!

Patricio

IMU_Data_with_Stripplot

1 Answers

Place two graphs of seaborn in GridSpec() of matplotlib. One is a strip plot and the other is a bar chart for the number of samples.

2 rows and 1 column, height ratio (4:1), top-to-bottom spacing: 0

gridspec.GridSpec(ncols=1, nrows=2, height_ratios=[4, 1], hspace=0)

full code:

import matplotlib.pyplot as plt
from matplotlib import gridspec
import seaborn as sns
sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")

fig = plt.figure()
spec = gridspec.GridSpec(ncols=1, nrows=2, height_ratios=[4, 1], hspace=0)

ax0 = fig.add_subplot(spec[0])
sns.stripplot(x="day", y="total_bill", data=tips, jitter=0.4, ax=ax0)
ax1 = fig.add_subplot(spec[1])
sns.barplot(x=tips.day.unique(), y=tips.groupby('day')['total_bill'].count().tolist(), ax=ax1)
ax1.set_ylabel('counts')

plt.show()

enter image description here

Related