-
Notifications
You must be signed in to change notification settings - Fork 2
/
1. Plotting the pitch.py
83 lines (55 loc) · 2.73 KB
/
1. Plotting the pitch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 22:56:58 2020
@author: Sathish
"""
from matplotlib.patches import Arc
import matplotlib.pyplot as plt
import matplotlib
def createPitch(length,width,linecolour,pitchcolour):
#Create figure
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
#Pitch Outline & Centre Line
plt.plot([0,0],[0,width], color=linecolour)
plt.plot([0,length],[width,width], color=linecolour)
plt.plot([length,length],[width,0], color=linecolour)
plt.plot([length,0],[0,0], color=linecolour)
plt.plot([length/2,length/2],[0,width], color=linecolour)
#Left Penalty Area
ax.plot([18 ,18],[(width/2 +18),(width/2-18)],color=linecolour)
ax.plot([0,18],[(width/2 +18),(width/2 +18)],color=linecolour)
ax.plot([18,0],[(width/2 -18),(width/2 -18)],color=linecolour)
#Right Penalty Area
ax.plot([(length-18),length],[(width/2 +18),(width/2 +18)],color=linecolour, zorder=2)
ax.plot([(length-18), (length-18)],[(width/2 +18),(width/2-18)],color=linecolour, zorder=2)
ax.plot([(length-18),length],[(width/2 -18),(width/2 -18)],color=linecolour, zorder=2)
#Left 6-yard Box
ax.plot([0,6],[(width/2+7.32/2+6),(width/2+7.32/2+6)],color=linecolour)
ax.plot([6,6],[(width/2+7.32/2+6),(width/2-7.32/2-6)],color=linecolour)
ax.plot([6,0],[(width/2-7.32/2-6),(width/2-7.32/2-6)],color=linecolour)
#Right 6-yard Box
ax.plot([length,length-6],[(width/2+7.32/2+6),(width/2+7.32/2+6)],color=linecolour)
ax.plot([length-6,length-6],[(width/2+7.32/2+6),width/2-7.32/2-6],color=linecolour)
ax.plot([length-6,length],[(width/2-7.32/2-6),width/2-7.32/2-6],color=linecolour)
#Prepare Circles; 10 yards distance. penalty on 12 yards
centreCircle = plt.Circle((length/2,width/2),10,color=linecolour,fill=False)
centreSpot = plt.Circle((length/2,width/2),0.4,color=linecolour)
leftPenSpot = plt.Circle((12,width/2),0.4,color=linecolour)
rightPenSpot = plt.Circle((length-12,width/2),0.4,color=linecolour)
#Prepare Arcs
leftArc = Arc((11,width/2),height=20,width=20,angle=0,theta1=312,theta2=48,color=linecolour)
rightArc = Arc((length-11,width/2),height=20,width=20,angle=0,theta1=130,theta2=230,color=linecolour)
#Remove axis
plt.axis('off')
rect1 = matplotlib.patches.Rectangle((-3,-3), length+6, length+12, color=pitchcolour)
#Display Circles and Arcs
ax.add_patch(rect1)
ax.add_patch(centreCircle)
ax.add_patch(centreSpot)
ax.add_patch(leftPenSpot)
ax.add_patch(rightPenSpot)
ax.add_patch(leftArc)
ax.add_patch(rightArc)
plt.show()
return fig,ax