ax1.plot(Close[-10:])
ax2.plot(Open[-10:])
plt.rcParams[‘font.sans-serif’] = [‘SimHei’] # 显示中文设置
ax1.set_title(‘近十个交易日收盘价’) # 设置标题
ax1.set_xlabel(‘日期’) # 设置X坐标轴标签
ax1.set_xticklabels(Close.index[-10:], rotation=25) # 设置刻度字体旋转角度
ax1.set_ylabel(‘收盘价’) # Y坐标轴标签
ax1.set_ylim(27,35) # Y坐标轴取值范围
ax2.set_title(‘近十个交易日开盘价’)
ax2.set_xlabel(‘日期’)
ax2.set_xticklabels(Close.index[-10:], rotation=25)
ax2.set_ylabel(‘开盘价’)
ax2.set_ylim(27,32)
2.1多个子图绘制
- 在实际绘图中,如果一个Figure对象包含多个Axes对象,每个Axes对象的位置除了通过区域坐标和长度来设定以外更常用的方式是通过子图subplot()函数来设定。
ax1=plt.subplot(221)
ax1.set_title(‘ax1’)
ax2=plt.subplot(222)
ax2.set_title(‘ax2’)
ax3=plt.subplot(223)
ax3.set_title(‘ax3’)
ax4=plt.subplot(224)
ax4.set_title(‘ax4’)
参数“221”中的“22”表示子图排列为2×2形式(2行2列),“1”表示第一个子图,默认次序为,先从第一行从左到右,再逐行向循环下计序。具体如图所示: