gpt4 book ai didi

python - 外线 Seaborn fiddle 图/箱线图

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:00 29 4
gpt4 key购买 nike

我正在使用 Seaborn 库中的 violinplot 函数。有时外线可视化: enter image description here

有时它们不是:enter image description here

这些示例基于相同的代码,但运行时间不同:

  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 错误造成的(请参阅此报告 issue )。

可以使用以下函数解决:

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))

可以通过以下方式修复示例:

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()

关于python - 外线 Seaborn fiddle 图/箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41567205/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com