plt.scatter error 'NoneType' object has no attribute 'sqrt' after running successfully

Viewed 1209

I have a code similar to the one below:

import matplotlib.pyplot as plt

a = [1,2,3]
b = [3,4,5]
plt.scatter(a,b)
plt.grid()
plt.yscale("linear")
plt.show()

The first couple times I run it, it works fine but afterwards it gives me the error:

'NoneType' object has no attribute 'sqrt'

which seems to be located somewhere deep in pyplot rather than it being a problem with my code. Is this something others have encountered?

2 Answers

If you are using a Jupyter Notebook with %matplotlib widget, it can be due to an interactive plot that hasn't been switched off. Try hitting the blue off button and try again.

In my case, I used Jupyter notebooks with %matplotlib notebook and interactive 3d plots. I replaced it with %matplotlib inline, restarted the kernel and it worked.

Related