2

I am trying to plot a swarplot on top of a violin plot. Is there any way to make the swarm width to be shortened just like the width option from violin plot?

Would it be easier to use a matplotlib.scatter to do it instead of seaborn.swarmplot?

import seaborn as sns
data = pd.read_csv('allparticles.csv')
b = sns.swarmplot(x="capsid", y="dT",hue="media",data=dataT,dodge=True,size=8)
c = sns.violinplot(x="capsid", y="dT",hue="media",inner="box",data=data ,width=0.3)

This results in something like this: enter image description here

I would like to make the swarmplot slimmer to match the violins.

My only other idea is to get the x min and max from the violin and plot it using matplotlib.

Thank you.

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
João Mamede
  • 129
  • 12

2 Answers2

0

The point of the swarm plot is to displace the points so that they don't overlap. You can see for example in the WT swarm plot that the width of the swarm is determined by the number of points which are close together, plus the width of each point. If you want the plots to be slimmer, you will have to make the points smaller. You can do this using the size parameter of sns.swarmplot.

Cai
  • 1,726
  • 2
  • 15
  • 24
0

We can make it similar by reducing the size of the points so that they match with the violin plot.

Try to vary the value of the size parameter:

b=sns.swarmplot(x="capsid",y="dT",hue="media",data=dataT,dodge=True,size=3,color="0.25")
Alexander Leithner
  • 3,169
  • 22
  • 33
Ravi
  • 2,778
  • 2
  • 20
  • 32