我正在使用 Seaborn 库中的 violinplot 函数。有时外线可视化:
有时它们不是:
这些示例基于相同的代码,但运行时间不同:
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()
我是一名优秀的程序员,十分优秀!