外线Seaborn violinplot/boxp

2024-04-19 15:00:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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()

如何操作外线的格式?在


Tags: columns函数代码示例dataframedfnp时间
1条回答
网友
1楼 · 发布于 2024-04-19 15:00:20

归功于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))

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

^{pr2}$

相关问题 更多 >