创建子图
fig = plt.figure(figsize=(4,3),dpi=100)
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(122)
等同于
fig, ax = plt.subplots(1,2,figsize=(4,3),dpi=100)
其中,fig
是图像对象,ax
是子图对象的元组组合。figsize控制每个子图的比例大小,dpi控制清晰度。
设置子图样式
fig, ax = plt.subplots(1, 2, figsize=(13,5), dpi=100)
ax[0].scatter(x1, y1, s=40)
ax[0].set_title("Top 5")
ax[0].set_xlabel('Value')
ax[0].set_ylabel('Cube of Value')
ax[1].plot(x2, y2)
ax[1].set_title('Top 5000')
ax[1].set_xlabel('Value')
ax[1].set_ylabel('Cube of Value')
在一个绘图上的时候的title(), xlabel(),xticks()
等,在绘制子图时变为了set_title(), set_xlabel(), set_xticks()
。
设置图像属性
plt.savefig('cube.png')
plt.show()