海运库中的despine函数似乎覆盖matplotlib中的字体设置参数。示例:
plt.figure()
plt.plot([1,2,3],[1,2,3])
plt.xticks([1,2,3], fontsize=13)
# despine blocks xtick labels font size
sns.despine(trim=True, offset=2)
plt.show()如果我注释掉sns.despine(trim=True, offset=2)行,那么plt.xticks的fontsize参数就能工作。如何使用despine而不让它覆盖我的字体大小设置?
发布于 2016-05-18 18:59:48
这是一个棘手的问题,我遇到了增加脊柱修剪/抵消功能到海运。你可以在这里看到我最初的问题:
Efficiently cache and restore matplotlib axes parameters after moving spines
在MPL邮件列表中提供了一些帮助之后,我们想出了一个解决方案:https://github.com/mwaskom/seaborn/blob/dfdd1126626f7ed0fe3737528edecb71346e9eb0/seaborn/utils.py#L288
看来这是我们工作时漏掉的一个边缘情况。
作为对您的解决办法,我建议您在格式化滴答之前先消除/抵消:
%matplotlib inline
from matplotlib import pyplot
import seaborn
fig, ax = pyplot.subplots()
# despine blocks xtick labels font size
seaborn.despine(trim=True, offset=2)
x = [1, 2, 3]
ax.plot(x, x)
ax.set_xticks(x)
ax.set_xticklabels(x, fontsize=13)

发布于 2016-05-11 19:26:01
尝试使用rcParams设置x抽签字体大小
import matplotlib as mpl
plt.figure()
mpl.rcParams['xtick.labelsize'] = 13 # must be place before the actual plot creation
plt.plot([1,2,3],[1,2,3])
# despine blocks xtick labels font size
sns.despine(trim=True, offset=2)
plt.show()这应该可以工作,并且仍然正确地应用despine。
https://stackoverflow.com/questions/37171384
复制相似问题