Существует ли / каков наилучший способ манипулирования значениями в новом фрейме данных в зависимости от значений графика?
В настоящее время у меня есть некоторые значения координат X и Y (см. Ниже пример ). И я хочу создать новый df, который будет умножать их, чтобы соответствовать графику, который у меня есть.
def draw_pitch(ax):
# size of the pitch is 120, 80
#Create figure
lines = "#02dbcc"
#Pitch Outline & Centre Line
plt.plot([0,0],[0,80], color=lines)
plt.plot([0,120],[80,80], color=lines)
plt.plot([120,120],[80,0], color=lines)
plt.plot([120,0],[0,0], color=lines)
plt.plot([60,60],[0,80], color=lines)
#Left Penalty Area
plt.plot([14.6,14.6],[57.8,22.2],color=lines)
plt.plot([0,14.6],[57.8,57.8],color=lines)
plt.plot([0,14.6],[22.2,22.2],color=lines)
#Right Penalty Area
plt.plot([120,105.4],[57.8,57.8],color=lines)
plt.plot([105.4,105.4],[57.8,22.5],color=lines)
plt.plot([120, 105.4],[22.5,22.5],color=lines)
#Left 6-yard Box
plt.plot([0,4.9],[48,48],color=lines)
plt.plot([4.9,4.9],[48,32],color=lines)
plt.plot([0,4.9],[32,32],color=lines)
#Right 6-yard Box
plt.plot([120,115.1],[48,48],color=lines)
plt.plot([115.1,115.1],[48,32],color=lines)
plt.plot([120,115.1],[32,32],color=lines)
#Prepare Circles
centreCircle = plt.Circle((60,40),8.1,color=lines,fill=False)
centreSpot = plt.Circle((60,40),0.71,color=lines)
leftPenSpot = plt.Circle((9.7,40),0.71,color=lines)
rightPenSpot = plt.Circle((110.3,40),0.71,color=lines)
#Draw Circles
ax.add_patch(centreCircle)
ax.add_patch(centreSpot)
ax.add_patch(leftPenSpot)
ax.add_patch(rightPenSpot)
#Prepare Arcs
# arguments for arc
# x, y coordinate of centerpoint of arc
# width, height as arc might not be circle, but oval
# angle: degree of rotation of the shape, anti-clockwise
# theta1, theta2, start and end location of arc in degree
leftArc = Arc((9.7,40),height=16.2,width=16.2,angle=0,theta1=310,theta2=50,color=lines)
rightArc = Arc((110.3,40),height=16.2,width=16.2,angle=0,theta1=130,theta2=230,color=lines)
#Draw Arcs
ax.add_patch(leftArc)
ax.add_patch(rightArc)
fig=plt.figure()
fig.set_facecolor("#313030")
fig.set_size_inches(7.5, 5.0)
ax=fig.add_subplot(1,1,1)
#ax.autoscale_view('tight')
draw_pitch(ax)
plt.axis('off')
plt.show()
#load JSON
with open("match.json",'r') as f:
data = json.load(f)
f.close()
#Get coordinates for shots
x_coords = ([float((k['X'])) * 100 for k in data['a']])
y_coords = ([float((k['Y'])) * 100 for k in data['a']])
coords = ([(float(k['X']) * 100, float(k['Y']) * 100) for k in data['a']])
#PLot shots
ax.scatter(x_coords, y_coords, c = "#ffff3b", label = 'shots')
Значения координат:
[(83.5999984741211, 38.599998474121094), (76.30000305175781, 64.0), (73.9000015258789, 44.29999923706055), (72.69999694824219, 46.599998474121094), (75.5999984741211, 35.5), (91.19999694824219, 66.5999984741211), (79.9000015258789, 47.599998474121094), (93.9000015258789, 67.5999984741211), (92.0, 52.400001525878906), (77.30000305175781, 37.099998474121094), (93.30000305175781, 48.70000076293945), (84.0, 71.5), (91.19999694824219, 42.900001525878906), (82.9000015258789, 28.299999237060547), (78.19999694824219, 64.80000305175781), (82.0999984741211, 64.30000305175781), (95.69999694824219, 55.70000076293945), (85.0999984741211, 70.0)]
По сути, в моем текущем примере, Я бы хотел умножить значения X и Y на 1,20 и 0,80, чтобы они соответствовали сюжету.
Я новичок в Python, поэтому извинения это трудно понять.