#import akshare as ak
import pandas as pd
import matplotlib.pyplot as plt
symbol1="资产负债表"
symbol2="利润表"
symbol3="现金流量表"
#df1=ak.stock_financial_report_sina(stock="601633",symbol=symbol1)
#df2=ak.stock_financial_report_sina(stock="601633",symbol=symbol2)
#df3=ak.stock_financial_report_sina(stock="601633",symbol=symbol3)
#df1.to_csv(f'{symbol1}.csv')
#df2.to_csv(f'{symbol2}.csv')
#df3.to_csv(f'{symbol3}.csv')
data1=pd.read_csv(f'{symbol1}.csv')
data2=pd.read_csv(f'{symbol2}.csv')
data3=pd.read_csv(f'{symbol3}.csv')
data1.index = pd.to_datetime(data1['报告日'], format='%Y%m%d')
data2.index = pd.to_datetime(data2['报告日'], format='%Y%m%d')
data3.index = pd.to_datetime(data3['报告日'], format='%Y%m%d')
data1=data1.fillna(0)
data2=data2.fillna(0)
data3=data3.fillna(0)
#有息负债率=(短期借款+1年内到期的长期负债+长期借款+应付债券+长期应付款)/总资产×100%
yxfz=data1['短期借款']+data1['一年内到期的非流动负债']+data1['长期借款']+data1['应付债券']+data1['长期应付款']
ibdr=yxfz/data1['资产总计']*100
#生产资产/总资产
sz=(data1['固定资产净值']+data1['在建工程合计'])/data1['资产总计']*100
#应收/总资产
yz=(data1['应收票据及应收账款']+data1['应收款项融资']+data1['应收股利']+data1['应收利息']/10000+data1['应收保费']+data1['应收分保账款']+data1['应收分保合同准备金']+data1['应收出口退税']+data1['应收补贴款']+data1['应收保证金']+data1['内部应收款']+data1['其他应收款']+data1['长期应收款'])/data1['资产总计']*100
#货币资金/有息负债
hy=data1['货币资金']/(data1['短期借款']+data1['一年内到期的非流动负债']+data1['长期借款']+data1['应付债券']+data1['长期应付款'])*100font1 = {'family': 'SimHei', 'weight': 'normal', 'size': 10}
clist=['blue','red','green','black','slategray','lime','gold','purple','green','cyan']
markerlst=['o','*','x','>','<','^','D','d','1','2','3','4']
linestylelst=['-','--','-.',':','-','--','-.',':','-','--','-.',':']
fig=plt.figure(1)
plt.rcParams['xtick.direction'] = 'in' # 将x周的刻度线方向设置向内
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内
# plt.rcParams['font.family'] = ["Times New Roman"] # 字体设置为Times NewRoman
plt.rcParams['font.sans-serif'] = ['SimHei']plt.plot(data1['报告日'],ibdr,c=clist[0], marker=markerlst[1], markersize='10', linewidth='3', linestyle=linestylelst[1], label='有息负债率')
plt.plot(data1['报告日'],sz,c=clist[1], marker=markerlst[2], markersize='10', linewidth='3', linestyle=linestylelst[2], label='生产资产/总资产')
plt.plot(data1['报告日'],yz,c=clist[2], marker=markerlst[3], markersize='10', linewidth='3', linestyle=linestylelst[3], label='应收/总资产')
#plt.plot(data['报告日'],hy,c=clist[3], marker=markerlst[4], markersize='10', linewidth='3', linestyle=linestylelst[4], label='货币资金/有息负债')# 图例展示位置,数字代表第几象限
plt.legend(bbox_to_anchor=(0.5,1.1),loc=9,prop=font1,ncol=3,framealpha=0.5)
#plt.xticks(xs)
#plt.yticks(np.linspace(0,0.16,11))
plt.grid(True, linestyle='--', alpha=0.5)
plt.xlabel("报告期", fontdict={'size': 16})
plt.ylabel("百分比(%)", fontdict={'size': 16})
fig.autofmt_xdate()fig=plt.figure(2)
plt.rcParams['axes.unicode_minus']=False
plt.rcParams['xtick.direction'] = 'in' # 将x周的刻度线方向设置向内
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内
# plt.rcParams['font.family'] = ["Times New Roman"] # 字体设置为Times NewRoman
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.plot(data3['报告日'],data3['经营活动产生的现金流量净额'],c=clist[0], marker=markerlst[1], markersize='10', linewidth='3', linestyle=linestylelst[1], label='经营活动产生的现金流量净额')
plt.plot(data3['报告日'],data3['投资活动产生的现金流量净额'],c=clist[1], marker=markerlst[2], markersize='10', linewidth='3', linestyle=linestylelst[2], label='投资活动产生的现金流量净额')
plt.plot(data3['报告日'],data3['筹资活动产生的现金流量净额'],c=clist[2], marker=markerlst[3], markersize='10', linewidth='3', linestyle=linestylelst[3], label='筹资活动产生的现金流量净额')
plt.plot(data2['报告日'],data2['净利润'],c=clist[3], marker=markerlst[4], markersize='10', linewidth='3', linestyle=linestylelst[4], label='净利润')
# 图例展示位置,数字代表第几象限
plt.legend(bbox_to_anchor=(0,1),loc=2,prop=font1,ncol=1,framealpha=0.5)
#plt.xticks(xs)
#plt.yticks(np.linspace(0,0.16,11))
plt.grid(True, linestyle='--', alpha=0.5)
plt.xlabel("报告期", fontdict={'size': 16})
plt.ylabel("元", fontdict={'size': 16})
fig.autofmt_xdate()fig=plt.figure(3)
plt.rcParams['axes.unicode_minus']=False
plt.rcParams['xtick.direction'] = 'in' # 将x周的刻度线方向设置向内
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内
# plt.rcParams['font.family'] = ["Times New Roman"] # 字体设置为Times NewRoman
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.plot(data3['报告日'],data3['期末现金及现金等价物余额'],c=clist[0], marker=markerlst[1], markersize='10', linewidth='3', linestyle=linestylelst[1], label='期末现金及现金等价物余额')
plt.plot(data1['报告日'],yxfz,c=clist[1], marker=markerlst[2], markersize='10', linewidth='3', linestyle=linestylelst[2], label='有息负债')
plt.plot(data3['报告日'],data3['销售商品、提供劳务收到的现金'],c=clist[2], marker=markerlst[3], markersize='10', linewidth='3', linestyle=linestylelst[3], label='销售商品、提供劳务收到的现金')
plt.plot(data2['报告日'],data2['营业收入'],c=clist[3], marker=markerlst[4], markersize='10', linewidth='3', linestyle=linestylelst[4], label='营业收入')
plt.plot(data3['报告日'],data3['现金及现金等价物净增加额']+data3['分配股利、利润或偿付利息所支付的现金'],c=clist[4], marker=markerlst[5], markersize='10', linewidth='3', linestyle=linestylelst[5], label='现金及现金等价物净增加额')
# 图例展示位置,数字代表第几象限
plt.legend(bbox_to_anchor=(0,1),loc=2,prop=font1,ncol=1,framealpha=0.5)
#plt.xticks(xs)
#plt.yticks(np.linspace(0,0.16,11))
plt.grid(True, linestyle='--', alpha=0.5)
plt.xlabel("报告期", fontdict={'size': 16})
plt.ylabel("元", fontdict={'size': 16})
fig.autofmt_xdate(bottom=0.2, rotation=30, ha='right')
plt.show()
![](https://img-blog.csdnimg.cn/daeffc2f05dd4e2cbd4522b996602aef.png)
![](https://img-blog.csdnimg.cn/2270745761894977bdbe914f262c919a.png)
![](https://img-blog.csdnimg.cn/449a9c24736d40a9a62830892a1ed4d6.png)