Python数据科学包(九)----- 球员能力图和股票K线图

一. 球员能力图

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('ggplot')

ability_size = 6
ability_label = ['attack','defence','wait','speed','patience','method']

player = {
    'M':np.random.randint(size=ability_size,low=60,high=99),
'H':np.random.randint(size=ability_size,low=60,high=99),
'P':np.random.randint(size=ability_size,low=60,high=99),
'Q':np.random.randint(size=ability_size,low=60,high=99)
}

theta = np.linspace(0,2*np.pi,6,endpoint=False)
theta = np.append(theta,theta[0])



ax1 = plt.subplot(221,projection='polar')
ax2 = plt.subplot(222,projection='polar')
ax3 = plt.subplot(223,projection='polar')
ax4 = plt.subplot(224,projection='polar')

player['M'] = np.append(player['M'],player['M'][0])
ax1.plot(theta,player['M'],'r')
ax1.fill(theta,player['M'],'r',alpha=0.3)
ax1.set_xticks(theta)
ax1.set_xticklabels(ability_label)
ax1.set_title('M',color='r',size=20

player['H'] = np.append(player['H'],player['H'][0])
ax2.plot(theta,player['H'],'g')
ax2.fill(theta,player['H'],'r',alpha=0.3)
ax2.set_xticks(theta)
ax2.set_xticklabels(ability_label)
ax2.set_title('H',color='g',size=20)

player['Q'] = np.append(player['Q'],player['Q'][0])
ax3.plot(theta,player['Q'],'r')
ax3.fill(theta,player['Q'],'r',alpha=0.3)
ax3.set_xticks(theta)
ax3.set_xticklabels(ability_label)
ax3.set_title('Q',color='r',size=20)

player['P'] = np.append(player['P'],player['P'][0])
ax4.plot(theta,player['P'],'r')
ax4.fill(theta,player['P'],'r',alpha=0.3)
ax4.set_xticks(theta)
ax4.set_xticklabels(ability_label)
ax4.set_title('P',color='r',size=20)

plt.show()

二. 股票K线图

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import quotes.historical_yahoo_ohlc,candlestick_ohlc

date1 = (2010,2,1)
date2 = (2010,5,1)
quotes = quotes_historical_yahoo_ohlc('INTC',date1,date2)

left,width = 0.1, 0.8
rect_vol = [left,0.1,width,0.26]
rect_main = [left,0.4,width,0.5]

volumns = np.array([])
dates = np.array([])

for record in quotes:
    dates = np.append(dates,record[0])
    volumns = np.append(volumns,record[5])
    
fig = plt.figure()

ax_vol = fig.add_axes(rect_vol)
ax_vol.fill_between(dates,volumns,color='y')
ax_vol.xaxis_date()
plt.setp(ax_vol.get_xticklabels(),rotation=30,horizontalalignment='right')


ax_main = fig.add_axes(rect_main)
candlestick_ohlc(ax_main,quotes,width=0.6,colorup='r',colordown='g')

ax_main.axes.get_xaxis().set_visible(False)

ax_main.set_title('Stock INTC Price and Volumn')

plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值