我正在使用Seaborn使用 whitegrid 样式制作一些图表。在调用 despine()之后,我发现与轴刺重叠的网格线的线宽比其他网格线要小。但似乎只有当我将这些图保存为pdf时才会发生这种情况。我在分享 三个不同的数字,具有不同的despine配置,显示效果。
有谁知道为什么会这样?还有一个简单的解决方法吗?
PDF plot that despines all axes
PDF plot that despines left, top, and right axes
代码:
splot = sns.boxplot(data=df, palette=color, whis=np.inf, width=0.5, linewidth = 0.5)
splot.set_ylabel('Normalized WS')
plt.xticks(rotation=90)
plt.tight_layout()
sns.despine(left=True, bottom=True)
plt.savefig('test.pdf', bbox_inches='tight')
答案 0 :(得分:1)
基本上,这里发生的是网格线以刻度位置为中心,因此极端网格线的外半部分不会被绘制,因为它们超出了轴的极限。
一种方法是禁用网格线的裁剪:
import numpy as np
import seaborn as sns
sns.set(style="whitegrid", rc={"grid.linewidth": 5})
x = np.random.randn(100, 6)
ax = sns.boxplot(data=x)
ax.yaxis.grid(True, clip_on=False)
sns.despine(left=True)
答案 1 :(得分:0)
我的黑客攻击解决方案现在是不要使顶部和底部轴平滑,并使它们与网格线的宽度相同。这不太理想。如果有人能指出解决根本原因的方法,我将非常感激。