1. 程式人生 > >Python學習筆記(matplotlib實戰篇)--球員能力圖

Python學習筆記(matplotlib實戰篇)--球員能力圖

Python學習筆記--球員能力圖

所用的庫及環境:

  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提供的文件,感謝麥子學院提供的視訊教學,感謝百度知道各位回答者的回答

      文章如哪裡有誤請聯絡作者QQ406802063,及時更正,感謝