0

'

pitchLength = 120
pitchWidth = 75
createPitch(pitchLength,pitchWidth,'meters','white')
ax = plt.subplot()
for index,col in rf_pass.iterrows():
    x_start = col['location'][0]
    y_start = col['location'][1]
    x_end = col['pass.end_location'][0]
    y_end = col['pass.end_location'][1]
    if col['period'] == 1 or col['period'] == 3:
        if(pitchLength - x_start < 60) and (col['play_pattern.name'] != 'From Throw In'):
            #pass_org = plt.Circle((pitchLength - x_start,y_start),radius = 3,color = 'red')
            pass_end = plt.plot(pitchLength - x_end,y_end,'c*', markersize=15)          
            #plt.text(pitchLength - x_start+2,y_start,col['minute'])
            #trip_pass.set_alpha(0.3)                
            #ax.add_patch(pass_org)
            ax.add_patch(pass_end)         
    elif col['period'] == 2 or col['period'] == 4:
        if(pitchLength - x_start < 60) and (col['play_pattern.name'] != 'From Throw In'):
            pass_org = plt.Circle((x_start,pitchWidth - y_start),radius = 3,color = 'blue')
            #trip_pass.set_alpha(0.3)
            ax.add_patch(pass_org)

'

I get the error

AttributeError Traceback (most recent call last)

<ipython-input-51-347f68947c51> in <module>()
     16             #trip_pass.set_alpha(0.3)
     17             #ax.add_patch(pass_org)
---> 18             ax.add_patch(pass_end)
     19     elif col['period'] == 2 or col['period'] == 4:
     20         if(pitchLength - x_start < 60) and (col['play_pattern.name'] != 'From Throw In'):

1 frames

/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_base.py in _set_artist_props(self, a)
    903     def _set_artist_props(self, a):
    904         """set the boilerplate props for artists added to axes"""
--> 905         a.set_figure(self.figure)
    906         if not a.is_transform_set():
    907             a.set_transform(self.transData)

AttributeError: 'list' object has no attribute 'set_figure'

This error happens when i use 'plt.plot' for pass_end, but when i use 'plt.Circle' function it works fine. I have trouble understanding how the sub_plot() works ? Why does it show error when i use the 'plt.plot()?

I was trying to plot the point with a different symbol, that's why i used the

plt.plot(pitchLength - x_end,y_end,'c*', markersize=15)

Is there any other way to introduce new symbols ?

Guna
  • 25
  • 7
  • Just remove `ax.add_patch(pass_end)`. The result of `plt.plot` is automatically added to the current `ax`. Preferably use `ax.plot` instead of `plt.plot` so there is no doubt to which `ax` the plot will be added. – JohanC May 22 '20 at 14:47
  • Thanks a lot , it worked ! But what exactly does the ax = plt.subplot() mean ? can i also use ax.Circle(), instead of plt.Circle() ? what will happen then ? I still don't seem to have a clear understanding on it. Can you explain it to me ? – Guna May 22 '20 at 16:23
  • Yes, things can get confusing. Especially as apart from matplotlib there also are seaborn and pandas plotting. The history of these, and the wish that a lot of old code keeps functioning, make that functions are not always consistent. It's hard to give a short introduction. The easiest way is to lookup examples of things similar to what you want and copy and modify that code. – JohanC May 22 '20 at 16:44
  • Some ideas for further reading: [the difference between `plt`, `ax` and `fìg`](https://stackoverflow.com/questions/37970424/what-is-the-difference-between-drawing-plots-using-plot-axes-or-figure-in-matpl)`, [the liffecycle of a plot](https://matplotlib.org/3.2.1/tutorials/introductory/lifecycle.html), [tutorials](https://matplotlib.org/3.2.1/tutorials). – JohanC May 22 '20 at 16:45
  • Appreciate it man ! Hope i get some clarity after this ! – Guna May 23 '20 at 07:36

1 Answers1

0

If the problem is just about creating different markers, adding marker="*" creates a star marker.

for example

plt.scatter(x,y)  #creates normal plot with circle marker
plt.scatter(x,y, marker="*")  #creates plot with star marker

I hope it works for you.

Suraj
  • 11
  • 3