Python 如何在Seaborn箱线图中编辑胡须、飞片、帽子等的属性

Python 如何在Seaborn箱线图中编辑胡须、飞片、帽子等的属性,python,pandas,matplotlib,boxplot,seaborn,Python,Pandas,Matplotlib,Boxplot,Seaborn,我使用Seaborn软件包创建了一个带有重叠条带图的嵌套箱线图。我在stackoverflow上看到了关于如何编辑和使用sns.boxplot生成的ax.artists的box属性的答案 是否有任何方法可以使用类似的方法编辑胡须、帽、飞片等属性?目前,我必须手动编辑seaborn->category.py文件中\u BoxPlotter()类的restyle\u boxplot方法中的值,以从默认绘图到所需绘图: 默认绘图: 所需绘图: 以下是我的代码供参考: sns.set_style('

我使用Seaborn软件包创建了一个带有重叠条带图的嵌套箱线图。我在stackoverflow上看到了关于如何编辑和使用sns.boxplot生成的ax.artists的box属性的答案

是否有任何方法可以使用类似的方法编辑胡须、帽、飞片等属性?目前,我必须手动编辑seaborn->category.py文件中
\u BoxPlotter()
类的
restyle\u 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)
sns.set_样式('whitegrid'))
图1,ax1=plt.subplot()
ax1=sns.boxplot(x=“Facility”,y=“%Savings”,hue=“Analysis”,
数据=总储蓄)

plt.setp(ax1.artists,fill=False)您需要编辑
Line2D
对象,这些对象存储在
ax.lines

下面是一个脚本,用于创建方框图(基于示例),然后根据问题中的样式编辑线条和艺术家(即,不填充,所有线条和标记颜色相同,等等)

您也可以修复图例中的矩形面片,但需要使用
ax.get\u legend().get\u patches()

我还将原始箱线图绘制在第二个轴上,作为参考

import matplotlib.pyplot as plt
import seaborn as sns

fig,(ax1,ax2) = plt.subplots(2)

sns.set_style("whitegrid")
tips = sns.load_dataset("tips")

sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set1", ax=ax1)
sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set1", ax=ax2)

for i,artist in enumerate(ax2.artists):
    # Set the linecolor on the artist to the facecolor, and set the facecolor to None
    col = artist.get_facecolor()
    artist.set_edgecolor(col)
    artist.set_facecolor('None')

    # Each box has 6 associated Line2D objects (to make the whiskers, fliers, etc.)
    # Loop over them here, and use the same colour as above
    for j in range(i*6,i*6+6):
        line = ax2.lines[j]
        line.set_color(col)
        line.set_mfc(col)
        line.set_mec(col)

# Also fix the legend
for legpatch in ax2.get_legend().get_patches():
    col = legpatch.get_facecolor()
    legpatch.set_edgecolor(col)
    legpatch.set_facecolor('None')

plt.show()

您能否举例说明如何更改方框子集的线条颜色?还有,你说每个补丁有6行,我在某处看到了完整的列表,但现在根本找不到。。。我该如何改变胡须和边缘,让中间带和传单保持原样?在对一个18个月前的答案的评论中,这是一个很大的问题。。。你最好问一个新问题