Reputation: 3242
I'm trying to plot multi-hue distributions with Seaborn, but I find that the plots are difficult to be traced back to the tick they belong to. I have tried to add a grid, but the grid is only showing on the dimension of the distribution, so separating the distribution itself but not different distributions from each other. Is it possible to have Seaborn add a grid line between different violin plot groups/hues? To illustrate, take one of the plots from the docs. I've added what I'd like to see to this plot (I've made the width of these separators quite heavy for illustration purposes, in the solution I'd like them to be just as thick as the grid lines):
Upvotes: 0
Views: 1510
Reputation: 80449
You could use matplotlib's axvline
to draw vertical lines at positions 0.5, 1.5, ...
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips, palette="muted")
for i in range(len(np.unique(tips['day'])) - 1):
ax.axvline(i + 0.5, color='grey', lw=1)
plt.show()
Alternatively, you could set minor ticks at these positions and turn the minor gridlines on for the x-axis.
Upvotes: 2