|
|
1
MMelnicki
6 年前
您可以使用
ax.text()
直接在绘图上打印文本。
-
使用
'transform=ax.transaxs->code>作为
ax.text()的参数,命令将允许您缩放轴,以便文本框的位置可以始终相同;我使用x=0.97和y=0.91粗略地在右上角获取它
这是测向仪:
‘coll_prop_6M’:0:0.06,1:0.0,2:0.0,3:0.1,4:0.25,5:0.66,6:0.02,7:0.12,8:0.04,9:0.22,10:0.73,11:0.45,\
sns.distplot(data.iloc[:,0],color=“SkyBlue”,ax=轴[0,0])
sns.distplot(data.iloc[:,2],color=“gold”,ax=轴[1,0])
对于i,ax表示枚举(axs.remaze(-1)):
背景色='white',颜色='xkcd:poo brown')
fontweight='demibold',fontsize=10,verticalAlignment='top',horizontalAlignment='right',\
请紧凑布局(
唱for i, ax in enumerate(axes) .reshape(-1) i 范围从1-4。
.iloc[:,i]
- 使用
'transform=ax.transAxes 命令允许您缩放轴,以便文本框的位置始终相同;我使用x=0.97和y=0.91粗略地将其置于右上角
data = pd.DataFrame({'coll_prop_tenure': {0: 0.04, 1: 0.0, 2: 0.0, 3: 0.06, 4: 0.38, 5: 0.61, 6: 0.01, 7: 0.1, 8: 0.04, 9: 0.22, 10: 0.72, 11: 0.39}, \
'coll_prop_12m': {0: 0.04, 1: 0.0, 2: 0.0, 3: 0.06, 4: 0.38, 5: 0.61, 6: 0.01, 7: 0.1, 8: 0.04, 9: 0.22, 10: 0.72, 11: 0.39}, \
'coll_prop_6m': {0: 0.06, 1: 0.0, 2: 0.0, 3: 0.1, 4: 0.25, 5: 0.66, 6: 0.02, 7: 0.12, 8: 0.04, 9: 0.22, 10: 0.73, 11: 0.45}, \
'coll_prop_3m': {0: 0.08, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.61, 6: 0.02, 7: 0.16, 8: 0.09, 9: 0.22, 10: 0.72, 11: 0.64}})
代码如下:
f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True)
sns.distplot(data.iloc[:,0], color="skyblue", ax=axes[0,0])
sns.distplot(data.iloc[:,1], color="olive", ax=axes[0,1])
sns.distplot(data.iloc[:,2], color="gold", ax=axes[1,0])
sns.distplot(data.iloc[:,3], color="teal", ax=axes[1,1])
for i, ax in enumerate(axes.reshape(-1)):
ax.text(x=0.97, y=0.97, transform=ax.transAxes, s="Skewness: %f" % data.iloc[:,i].skew(),\
fontweight='demibold', fontsize=10, verticalalignment='top', horizontalalignment='right',\
backgroundcolor='white', color='xkcd:poo brown')
ax.text(x=0.97, y=0.91, transform=ax.transAxes, s="Kurtosis: %f" % data.iloc[:,i].kurt(),\
fontweight='demibold', fontsize=10, verticalalignment='top', horizontalalignment='right',\
backgroundcolor='white', color='xkcd:dried blood')
plt.tight_layout()
|