我正在尝试在我的折叠式箱形图上实现垂直线以分隔每一列,到目前为止,我似乎只能添加贯穿中间的主要行ax.xaxis.grid(True, which='major')
。这是我的代码和我要实现的图像。谢谢!
# Custom palette
my_pal = {"Year A": "#e42628", "Year B": "#377db6"}
plt.figure(figsize=(16, 10))
sns.axes_style("whitegrid")
ax = sns.boxplot(x='variable', y="value", hue="Condition", showmeans=True, data=df, palette=my_pal, meanprops={"marker":"s","markerfacecolor":"white", "markeredgecolor":"black"})
plt.ylabel("Temperature (\xb0C)")
#ax.axvline(linewidth=2, color='r')
ax.xaxis.grid(True, which='major')
答案 0 :(得分:2)
箱形图的默认宽度为0.5(如果较小,则为0.15 x [极限位置之间的距离])。
如果宽度为0.5,则可以执行以下操作:
import seaborn as sns, matplotlib.pyplot as plt
tips = sns.load_dataset('tips')
ax = sns.boxplot(x='day',y='total_bill',hue='sex',data=tips)
[ax.axvline(x+.5,color='k') for x in ax.get_xticks()]
plt.show()
答案 1 :(得分:2)