Python学习笔记(matplotlib实战篇)--球员能力图

Python学习笔记--球员能力图

  参靠视频:《Python数据可视化分析 matplotlib教程》链接:https://www.bilibili.com/video/av6989413/?p=6

所用的库及环境:

  IDE:Pycharm

  Python环境:python3.7

  Matplotlib:   Matplotlib 1.11

  Numpy:  Numpy1.15

球员能力图(本图数据均是随机生成,不代表任何事情)

  • 前言
    • 利用极坐标绘制球员能力图
    • 画出如下图形

  • 代码
 1 # coding=<utf-8>
 2 import  numpy as np
 3 import  matplotlib.pyplot as plt
 4 from matplotlib.font_manager import *
 5 
 6 
 7 plt.style.use('ggplot')
 8 #解决中文显示的为框框
 9 font =FontProperties(fname =r'C:\Windows\Fonts\simfang.ttf',size=12)
10 
11 #能力
12 ability_size = 6
13 ability_labels = [u'进攻',u'防守',u'盘带',u'速度',u'体力',u'射术']#转化为Unicode
14 
15 #构造画布
16 ax1= plt.subplot(221,projection = 'polar')
17 ax2= plt.subplot(222,projection = 'polar')
18 ax3= plt.subplot(223,projection = 'polar')
19 ax4= plt.subplot(224,projection = 'polar')
20 
21 #取消网格
22 
23 ax1.grid(False)
24 ax2.grid(False)
25 ax3.grid(False)
26 ax4.grid(False)
27 
28 
29 #构造球员能力,随机生成的
30 player = {
31     'M':np.random.randint(size=ability_size,low=60,high=90),
32     'H':np.random.randint(size=ability_size,low=60,high=90),
33     'P':np.random.randint(size=ability_size,low=60,high=90),
34     'Q':np.random.randint(size=ability_size,low=60,high=90),
35 }
36 
37 #角度,最后一个和第一个重合
38 theta = np.linspace(0,2*np.pi,6,endpoint=False)
39 theta = np.append(theta,theta[0])
40 
41 
42 #绘制MX的图
43 player ['M'] = np.append(player['M'],player['M'][0])
44 ax1.plot(theta,player['M'],'r')
45 ax1.fill(theta,player['M'],'r',alpha =0.3 )
46 ax1.set_xticks(theta)#分成六等分
47 ax1.set_xticklabels(ability_labels,y = 0.01,fontproperties= font)#指定字体和y坐标
48 ax1.set_title(u'MX',fontproperties = font,color = 'r',size=20)
49 ax1.set_yticks([20,40,60,80,100])
50 
51 #绘制HW的图
52 player ['H'] = np.append(player['H'],player['H'][0])
53 ax2.plot(theta,player['H'],'g')
54 ax2.fill(theta,player['H'],'g',alpha =0.3 )
55 ax2.set_xticks(theta)#分成六等分
56 ax2.set_xticklabels(ability_labels,y = 0.01,fontproperties= font)#指定字体和y坐标
57 ax2.set_title(u'HW',fontproperties = font,color = 'g',size=20)
58 ax2.set_yticks([20,40,60,80,100])
59 
60 #绘制PK的图
61 player ['P'] = np.append(player['P'],player['P'][0])
62 ax3.plot(theta,player['P'],'#A020F0')
63 ax3.fill(theta,player['P'],'#A020F0',alpha =0.3 )
64 ax3.set_xticks(theta)#分成六等分
65 ax3.set_xticklabels(ability_labels,y = 0.01,fontproperties= font)#指定字体和y坐标
66 ax3.set_title(u'PK',position  = (0.5,1),fontproperties = font,color = '#A020F0',size=20)
67 ax3.set_yticks([20,40,60,80,100])
68 
69 #绘制QH的图
70 player ['Q'] = np.append(player['Q'],player['Q'][0])
71 ax4.plot(theta,player['Q'],'y')
72 ax4.fill(theta,player['Q'],'y',alpha =0.3 )
73 ax4.set_xticks(theta)#分成六等分
74 ax4.set_xticklabels(ability_labels,y = 0.01,fontproperties= font)#指定字体和y坐标
75 ax4.set_title(u'QH',position  = (0.5,1),fontproperties = font,color = 'y',size=20,y=1)
76 ax4.set_yticks([20,40,60,80,100])
77 
78 plt.show()

      感谢matplotlib,numply提供的文档,感谢麦子学院提供的视频教学,感谢百度知道各位回答者的回答

posted @ 2018-09-22 16:37  9974  阅读(1872)  评论(1编辑  收藏  举报
快递查询