外线 Seaborn violinplot/boxplot [英] Outer lines Seaborn violinplot/boxplot
本文介绍了外线 Seaborn violinplot/boxplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Seaborn 库中的 violinplot 函数.有时外线是可视化的:
I am using the violinplot function from the Seaborn library. Sometimes the outer lines are visualized:
有时它们不是:
这些示例基于相同的代码,运行时间不同:
These examples are based on the same bit of code, running different times:
df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))
sns.violinplot(data=df, order=list(df.columns), cut=0,inner='points', bw='silverman', split=True, color='limegreen')
plt.show()
如何操作外线的格式?
推荐答案
感谢 Serenity 指出这是由于 matplotlib 错误(请参阅此报告的问题).
Credits to Serenity for pointing out that this is due to a matplotlib bug (see this reported issue).
可以使用以下函数解决:
It can be solved by using the following function:
def patch_violinplot():
from matplotlib.collections import PolyCollection
ax = plt.gca()
for art in ax.get_children():
if isinstance(art, PolyCollection):
art.set_edgecolor((0.3, 0.3, 0.3))
修复示例可以通过以下方式完成:
Fixing the example can be done by:
df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))
sns.violinplot(data=df, order=list(df.columns), cut=0,inner='points', bw='silverman', split=True, color='limegreen')
patch_violinplot()
plt.show()
这篇关于外线 Seaborn violinplot/boxplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文