matplotlib实例

1173-杨同学

发表文章数:29

首页 » 数据科学库 » 正文

球员能力图

matplotlib实例

#_*_coding:utf-8 _*_
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import  FontProperties
import matplotlib.patches as mpatches
plt.style.use('ggplot')
font=FontProperties(fname=r'c:/windows/fonts/simsun.ttc',size=18)
ability_size=6
ability_label=[u'进攻',u'防守',u'盘带',u'速度',u'体力',u'射术']
ax1=plt.subplot(221,projection='polar')
ax2=plt.subplot(221,projection='polar')
ax3=plt.subplot(221,projection='polar')
ax4=plt.subplot(221,projection='polar')
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])

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,y=0.1,fontproperties=font)
ax1.set_title(u'梅西',position=(0.5,1.01),fontproperties=font,color='r',size=20)
ax1.set_yticks([20,40,60,80,100])
player['H']=np.append(player['H'],player['H'][0])
ax2.plot(theta,player['H'],'g')
ax2.fill(theta,player['H'],'g',alpha=0.3)
ax2.set_xticks(theta)
ax2.set_xticklabels(ability_label,y=0.1,fontproperties=font)
ax2.set_title(u'哈维',position=(0.5,1.01),fontproperties=font,color='r',size=20)
ax2.set_yticks([20,40,60,80,100])
player['P']=np.append(player['P'],player['P'][0])
ax3.plot(theta,player['P'],'b')
ax3.fill(theta,player['P'],'b',alpha=0.3)
ax3.set_xticks(theta)
ax3.set_xticklabels(ability_label,y=0.1,fontproperties=font)
ax3.set_title(u'皮克',position=(0.5,1.01),fontproperties=font,color='r',size=20)
ax3.set_yticks([20,40,60,80,100])
player['Q']=np.append(player['Q'],player['Q'][0])
ax4.plot(theta,player['Q'],'y')
ax4.fill(theta,player['Q'],'y',alpha=0.3)
ax4.set_xticks(theta)
ax4.set_xticklabels(ability_label,y=0.1,fontproperties=font)
ax4.set_title(u'切赫',position=(0.5,1.01),fontproperties=font,color='r',size=20)
ax4.set_yticks([20,40,60,80,100])
plt.show()

股票K线图

matplotlib实例

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import quotes_historical_yahoo_ohlc,candlestick_ohlc
plt.style.use('ggplot')
date1=(2010,2,1)
date2=(2010,5,1)
quotes=quotes_historical_yahoo_ohlc('INTC',date1,date2)

volumns=np.array([])
dates=np.array([])
for record in quotes:
    dates=np.append(dates,record[0])
    volumns=np.append(volumns,record[5],color='y')
left,width=0.1,0.8
rect_vol=[left,0.1,width,0.26]
rect_main=[left,0.4,width,0.5]
fig=plt.figure()
ax_vol=fig.add_axes(rect_vol)
ax_vol.fill_between(dates,volumns)
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_xaxix().set_visible(False)
ax_main.set_title('Stock INTC Price and Volumn')
plt.show()

未经允许不得转载:作者:1173-杨同学, 转载或复制请以 超链接形式 并注明出处 拜师资源博客
原文地址:《matplotlib实例》 发布于2020-07-19

分享到:
赞(0) 打赏

评论 抢沙发

评论前必须登录!

  注册



长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

Vieu3.3主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录