Adjusting the space between datapoints on a seaborn swarm/scatter plot

Viewed 74

I am searching for a way to adjust the space between data points (red arrows) and between the x-ticks (green arrows) on a seaborn strip- or swarm-plot.

seaborn stripplot with given dataset

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = {'Days': np.full((48, 5), [4,7, 8, 9, 10]).reshape(-1),
        'Group': np.full((80, 3), ["Group1", "Group2", "Group3"]).reshape(-1), 
        'Value': np.random.rand(240)}
df = pd.DataFrame(data=data)
fig, ax = plt.subplots(figsize=(20, 10), dpi=80)
sns.stripplot(x=df.Days, y=df.Value, jitter=0, size=5, ax=ax, linewidth=1,
              dodge=True, hue=df.Group, palette="Set1", data=df)
plt.show()
1 Answers

The strip plot provides functionality called jitter which makes it an advantage to visualize the collision of data as shown in the image below. However, to adjust the space you should adjust the jitter in the strip plot method to a number greater than zero. you can make it 5 for example or any number that is appropriate for u.

sns.stripplot(x=df.Days, y=df.Value, jitter=5, data=df)

Moreover, u can see this video to understand more about strip plot https://www.youtube.com/watch?v=wNgxdH02hrw

see the image

Related