python_matplotlib DAY_23(1) draw FIFA, live player ability map

Learn to draw
Polar coordinate drawing
TIPS:
Friends will be more or less exposed to FIFA, live and other football games. The player's ability map can intuitively reflect a player's ability level. Start drawing a player's ability map today to experience it. My own feeling of being a character designer
Model analysis
1. Use polar coordinates to draw a closed image
2. Draft 4 players
3. Choose six player abilities, physical strength, shooting, defense, physical strength, offense, and speed, which shows the extreme The angle axis of the coordinate needs to be divided into 6 equal parts
. 4. Filling and annotation are completed, which is more intuitive

Design steps
1. Complete the prerequisite steps for labels, data, packages, etc.

import numpy as np
import matplotlib.pyplot as plt#画图必备

ability_label = ['盘带', '射术', '体力', '进攻', '防守',u'速度']
theta = [0, np.pi / 3, 2 * np.pi / 3, np.pi, 4 * np.pi / 3, 5 * np.pi / 3, 0]
player = {
    
    
    "M": np.random.randint(60, 99, 6),
    "H": np.random.randint(60, 99, 6),
    "P": np.random.randint(60, 99, 6),
    "Q": np.random.randint(60, 99, 6),
}#初步数据完成,因为绘制极坐标,所以是距离加角度联合控制
player["M"] = np.append(player["M"], player["M"][0])
#因为数据是随机产生的,而且我们需要花封闭图型,无法导致首尾闭合
#所以使用np的appned操作,让最后一维数据与第一位相等,画出闭合图像

2. Draw the image

fig = plt.figure()
plt.style.use("ggplot")
ax1 = fig.add_subplot(111, projection='polar')#使用极坐标
ax1.plot(theta, player["M"], 'r')

Preliminary image
3. Modifications and comments
We have defined 6 data, but there are 8 axis scales.
Secondly, we have not completed the internal filling.
Then we have to complete the name modification of the axis and
finally add the title

ax1.fill(theta, player["M"], 'r', alpha=0.3)#内部填充
ax1.set_xticks(theta)#将角度划分成我们定义的theta
ax1.set_xticklabels(ability_label)#将调度的坐标设置标签
ax1.set_yticks([20, 40, 60, 80, 100])#设置距离标签
ax1.set_title('梅西', position=(0.5, 1))#加上标题

Semi-finished image
4. Text display
Because Chinese cannot be displayed, I checked a lot of information. The easiest way is
to import it in the code as follows

from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
#同时我们要在中文前面加上u

Later experiments found that the display can be completed with or without u
Finished picture

The remaining three friends can try it yourself

5. The complete code is as follows

from pylab import mpl

mpl.rcParams['font.sans-serif'] = ['SimHei']

import numpy as np
import matplotlib.pyplot as plt

ability_label = [u'盘带', u'射术', u'体力', u'进攻', u'防守', u'速度']
theta = [0, np.pi / 3, 2 * np.pi / 3, np.pi, 4 * np.pi / 3, 5 * np.pi / 3, 0]
player = {
    
    
    "M": np.random.randint(60, 99, 6),
    "H": np.random.randint(60, 99, 6),
    "P": np.random.randint(60, 99, 6),
    "Q": np.random.randint(60, 99, 6),
}
fig = plt.figure()
plt.style.use("ggplot")
ax1 = fig.add_subplot(111, 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_yticks([20, 40, 60, 80, 100])
ax1.set_title(u'梅西', position=(0.5, 1))

plt.show()

Guess you like

Origin blog.csdn.net/soulproficiency/article/details/104121736