先贴三张图,
上图
代码
图一
import tushare as ts
import matplotlib.pyplot as plt
import numpy as np
plt.text(a, b+0.05, '%.2f'%b, ha='center', va='bottom', fontsize=7)
plt.show()
图二
import tushare as ts
import matplotlib.pyplot as plt
import numpy as np
print 'please input the year'
year1 = input()
year2 = input()
year3 = input()
year4 = input()
year5 = input()
timelist = []
timelist.append(year1)
timelist.append(year2)
timelist.append(year3)
timelist.append(year4)
timelist.append(year5)
print 'please input the stock code'
scode = input()
roe = []
net_profit_ratio = []
gross_profit_rate = []
net_profits = []
eps = []
business_income = []
bips = []
for i in timelist:
profit_data = ts.get_profit_data(i,4)
profit_data.index = profit_data.code
data = profit_data[profit_data.index == scode]
roe.append(float(data.roe))
net_profit_ratio.append(float(data.net_profit_ratio))
gross_profit_rate.append(float(data.gross_profit_rate))
net_profits.append(float(data.net_profits))
eps.append(float(data.eps))
business_income.append(float(data.business_income))
bips.append(float(data.bips))
plt.figure(figsize=(12,6))
#营业收入柱状图
plt.subplot(231)
ind = np.arange(5)
plt.bar(ind, business_income, color='yellowgreen')
plt.title('Business Income(BaiWan Yuan)')
plt.xticks(ind, (year1, year2, year3, year4, year5))
for a, b in zip(ind, business_income):
plt.text(a, b+0.05, '%.2f'%b, ha='center', va='bottom', fontsize=7)
#净利润柱状图
plt.subplot(232)
ind = np.arange(5)
plt.bar(ind, net_profits, color='gold')
plt.title('Net_profits(Wan Yuan)')
plt.xticks(ind, (year1, year2, year3, year4, year5))
for a, b in zip(ind, net_profits):
plt.text(a, b+0.05, '%.2f'%b, ha='center', va='bottom', fontsize=7)
#每股收益柱状图
plt.subplot(233)
ind = np.arange(5)
plt.bar(ind, eps, color='#FFA500')
plt.title('EPS')
plt.xticks(ind, (year1, year2, year3, year4, year5))
for a, b in zip(ind, eps):
plt.text(a, b+0.05, '%.2f'%b, ha='center', va='bottom', fontsize=7)
#roe折线图
plt.subplot(234)
plt.title('ROE(%)')
plt.plot(roe, 'r', label='ROE')
plt.xticks(ind, (year1, year2, year3, year4, year5))
#净利润率折线图
plt.subplot(235)
plt.title('Net_Profit_Ratio(%)')
plt.plot(net_profit_ratio, 'b', label='Net_Profit_Ratio')
plt.xticks(ind, (year1, year2, year3, year4, year5))
#毛利率折线图
plt.subplot(236)
plt.title('Gross_Profit_Rate(%)')
plt.plot(gross_profit_rate, 'g', label='Gross_Profit_Ratio')
plt.xticks(ind, (year1, year2, year3, year4, year5))
plt.show()
图三
import tushare as ts
import matplotlib.pyplot as plt
import numpy as np
print 'please input the year'
year1 = input()
year2 = input()
year3 = input()
year4 = input()
year5 = input()
timelist = []
timelist.append(year1)
timelist.append(year2)
timelist.append(year3)
timelist.append(year4)
timelist.append(year5)
print 'please input the stock code'
scode = input()
arturnover = []
arturndays = []
inventory_turnover = []
inventory_days = []
currentasset_turnover = []
currentasset_days = []
for i in timelist:
operation_data = ts.get_operation_data(i,4)
operation_data.index = operation_data.code
data = operation_data[operation_data.index == scode]
arturnover.append(float(data.arturnover))
arturndays.append(float(data.arturndays))
inventory_turnover.append(float(data.inventory_turnover))
inventory_days.append(float(data.inventory_days))
currentasset_turnover.append(float(data.currentasset_turnover))
currentasset_days.append(float(data.currentasset_days))
plt.figure(figsize=(12,6))
ind = np.arange(5)
#应收账款折线图
plt.subplot(231)
plt.title('AR Turnover(ci)')
plt.plot(arturnover, 'r', label='AR Turnover')
plt.xticks(ind, (year1, year2, year3, year4, year5))
#存货折线图
plt.subplot(232)
plt.title('Inventory Turnover(ci)')
plt.plot(inventory_turnover, 'b', label='Inventory Turnover')
plt.xticks(ind, (year1, year2, year3, year4, year5))
#流动资产折线图
plt.subplot(233)
plt.title('CA Turnover(ci)')
plt.plot(currentasset_turnover, 'g', label='CA Turnover')
plt.xticks(ind, (year1, year2, year3, year4, year5))
#应收账款柱状图
plt.subplot(234)
plt.bar(ind, arturndays, color='yellowgreen')
plt.title('AR Turnover Days')
plt.xticks(ind, (year1, year2, year3, year4, year5))
for a, b in zip(ind, arturndays):
plt.text(a, b+0.05, '%.2f'%b, ha='center', va='bottom', fontsize=7)
#存货柱状图
plt.subplot(235)plt.show()