pythonmatplotlibseabornswarmplot

Python: swarm plot covers the median line in box plot


When plotting a swarm plot (seaborn) over a box plot, the points may cover the median line of a box plot. How can I do the swarm plots dots a bit more transparent so that I also see the median of a box plot?

On the plot we do not see the median line because it is covered by the dot, so, optically I do not know where the median is on the second box. Is it possible to do the points of the swarm plot more transparent so that I also see the median line?

Example:

fig, axes = plt.subplots(nrows=1, ncols=1,figsize=(6,2))
data = pd.DataFrame({'a':[3,3,3,3,4,5,6,8,11,11,8,7,7,7,7,7,7,3,3,3,3,3,7,7,7,7,7,7,7,7,7,7,7,8,9,10,11,12,11,11,11]})
sns.boxplot(x='a',data=data, ax = axes)
ax = sns.swarmplot(x='a', data=data, color = 'grey', ax = axes)

(Making a larger figure is not an option)

enter image description here


Solution

  • Two options come directly to my mind:

    Of course any combination of the two options can help as well.