我用factorplotin seaborn和get facetgrid对象绘制了我的数据,但仍无法理解如何在这样的情节中设置以下属性:
Pau*_*l H 83
您可以扩大通话中的字体sns.set().
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x = np.random.normal(size=37)
y = np.random.lognormal(size=37)
# defaults
sns.set()
fig, ax = plt.subplots()
ax.plot(x, y, marker='s', linestyle='none', label='small')
ax.legend(loc='upper left', bbox_to_anchor=(0, 1.1))
Run Code Online (Sandbox Code Playgroud)

sns.set(font_scale=5) # crazy big
fig, ax = plt.subplots()
ax.plot(x, y, marker='s', linestyle='none', label='big')
ax.legend(loc='upper left', bbox_to_anchor=(0, 1.3))
Run Code Online (Sandbox Code Playgroud)

ach*_*nnu 24
该FacetGrid图确实产生了非常小的标签.虽然@ paul-h已经描述了使用sns.set作为改变字体缩放的方法,但它可能不是最佳解决方案,因为它将改变font_scale所有绘图的设置.
您可以使用它seaborn.plotting_context来更改当前图表的设置:
with sns.plotting_context(font_scale=1.5):
sns.factorplot(x, y ...)
Run Code Online (Sandbox Code Playgroud)
Ser*_*obo 14
我对@paul-H 代码做了一些小的修改,这样你就可以独立设置 x/y 轴和图例的字体大小。希望能帮助到你:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x = np.random.normal(size=37)
y = np.random.lognormal(size=37)
# defaults
sns.set()
fig, ax = plt.subplots()
ax.plot(x, y, marker='s', linestyle='none', label='small')
ax.legend(loc='upper left', fontsize=20,bbox_to_anchor=(0, 1.1))
ax.set_xlabel('X_axi',fontsize=20);
ax.set_ylabel('Y_axis',fontsize=20);
plt.show()
Run Code Online (Sandbox Code Playgroud)
这是输出:
对于图例,您可以使用此
plt.setp(g._legend.get_title(), fontsize=20)
Run Code Online (Sandbox Code Playgroud)
其中 g 是调用创建它的函数后返回的 facetgrid 对象。