python - 外线 Seaborn fiddle 图/箱线图

标签 python matplotlib seaborn

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

相关文章:

python - 识别对象,为什么 id(...) 的返回值会改变?

python-3.x - Pandas 从多索引级别获取所有值

python-3.x - Seaborn 中分组箱线图的单独颜色

matplotlib - 带有 Seaborn 联合网格图的多个边缘图

python - 重新采样 Pandas 列日期时间

python - 如何使用搜索到的字符串作为引用来替代 python re?

python - 为什么我得到 [SSL : CERTIFICATE_VERIFY_FAILED] in Python when ssl setup looks OK?

python - 指定刻度标签的浮点格式

python - ipython笔记本中的绘图宽度设置

python - seaborn clustermap 不会重新排列注释数据