【发布时间】:2016-08-20 20:36:03
【问题描述】:
我使用 Seaborn 包创建了一个带有重叠条形图的嵌套箱线图。我在 stackoverflow 上看到了有关如何使用 sns.boxplot 生成的 ax.artists 为 individual boxes 和 all boxes 编辑 box 属性的答案。
有没有办法使用类似的方法来编辑胡须、帽子、传单等属性?目前,我必须手动编辑 seaborn -> categorical.py 文件中 _BoxPlotter() 类的 restyle_boxplot 方法中的值,以从默认绘图到所需绘图:
这是我的参考代码:
sns.set_style('whitegrid')
fig1, ax1 = plt.subplots()
ax1 = sns.boxplot(x="Facility", y="% Savings", hue="Analysis",
data=totalSavings)
plt.setp(ax1.artists,fill=False) # <--- Current Artist functionality
ax1 = sns.stripplot(x="Facility", y="% Savings", hue="Analysis",
data=totalSavings, jitter=.05,edgecolor = 'gray',
split=True,linewidth = 0, size = 6,alpha = .6)
ax1.tick_params(axis='both', labelsize=13)
ax1.set_xticklabels(['Test 1','Test 2','Test 3','Test 4','Test 5'], rotation=90)
ax1.set_xlabel('')
ax1.set_ylabel('Percent Savings (%)', fontsize = 14)
handles, labels = ax1.get_legend_handles_labels()
legend1 = plt.legend(handles[0:3], ['A','B','C'],bbox_to_anchor=(1.05, 1),
loc=2, borderaxespad=0.)
plt.setp(plt.gca().get_legend().get_texts(), fontsize='12')
fig1.set_size_inches(10,7)
【问题讨论】:
标签: python pandas matplotlib boxplot seaborn