废话不多说,直接上干货,这是一个简单的双Y图绘制,目前我pandas版本是0.25,运行结果没有问题,且我的anaconda是二月中旬从官网下载的,按理说库都是最新的,而后同事测试代码15行疯狂报错
%matplotlib inline
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname='./data/STSONG.TTF',size=18)
# 获取数据
datas = pd.read_excel('./data/600001SH.xlsx')
datas.index = pd.to_datetime(datas['日期'])
feb_datas = datas['2015-02']
# 绘制图形
fig = plt.figure(figsize=(20,8),dpi=80)
ax = fig.add_subplot(111)
lin1 = ax.plot(feb_datas.index.tolist(),feb_datas['开盘价(元)'].values.tolist(),label='开盘价',color='red')
ax.set_ylabel("开盘价(元)",fontproperties=my_font)
ax.set_xlabel("日期",fontproperties=my_font)
ax.legend(prop=my_font)
ax2 = ax.twinx()
lin2 = ax2.plot(feb_datas.index.tolist(),feb_datas['成交量(股)'].values.tolist(),label='成交量(股)')
ax2.legen