0

I have been trying working with matplotlib and suddenly it stopped working. Whenever I call:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection = '3d')

ax.scatter(fb_df['r'], fb_df['g'], fb_df['b'])

plt.show()

I have the following error returned:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-7d1c064ffc44> in <module>
      3 ax = fig.add_subplot(projection = '3d')
      4 
----> 5 ax.scatter(fb_df['r'], fb_df['g'], fb_df['b'])
      6 #ax.set_xlabel('R')
      7 #ax.set_ylabel('G')

AttributeError: 'NoneType' object has no attribute 'scatter'

I am going crazy because it makes no sense to me. I tried uninstalling and reinstalling matplotlib, I also tried closing and reopening jupyter notebooks.

Jeff Gallini
  • 35
  • 2
  • 5
  • Are you sure you are using the latest version of matplotlib? You also might try to add `from mpl_toolkits.mplot3d import Axes3D` , which was needed in older matplotlib versions. ([old tutorial](https://matplotlib.org/2.0.2/mpl_toolkits/mplot3d/tutorial.html)) – JohanC May 25 '21 at 06:10
  • It was working yesterday morning and then randomly stopped working. I know it is not the projection that is causing the problem. Further in my code I call ax = fig.add_subplot() ax.scatter(df['width'], -df['height'], c = df['hex']) and I am having the same problem – Jeff Gallini May 25 '21 at 12:27
  • Looks like it's the version of matplotlib. Check this out: https://stackoverflow.com/questions/56632987/matplotlib-figure-figure-add-subplots-and-add-axes-return-none-instead-of-ax – RMiller Apr 15 '22 at 02:50

1 Answers1

0

I was able to find a workaround. But it is significantly slower.

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(fb_df['r'], fb_df['g'], fb_df['b'])
ax.set_xlabel('R')
ax.set_ylabel('G')
ax.set_zlabel('B')
ax.set_title("Georgia Tech Football Scatterplot")
plt.show()
Jeff Gallini
  • 35
  • 2
  • 5