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