一. 球员能力图
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()