Pycharm Cannot find reference 'linspace' in matplotlib.pyplot

Viewed 425

I'm trying to plot a graph in my pycharm ide using the matplotlib library. But I am unable to do so. Because Pycharm shows me this message : Cannot find reference 'linspace' in 'init.pyi | init.pyi' Here's my code =

x=[[1,2,3],[4,5,6],[7,8,9]]
import numpy as np
import matplotlib.pyplot as plt
a=np.array(x)
print(a)
x = np.linspace(0, 10, 100)
y= x ** 2
plt.plot(x,y)

Can anyone tell me what I'm doing wrong?

2 Answers

It is an issue that occurred after numpy devs switched approach to exposing public stubs in version 1.20. The re-imports in numpy/__init__.pyi were left without as keyword, which made them private. Those imports were instead added to __all__, but PyCharm wasn't supporting this approach.

It was fixed in PyCharm 2020.3.3. So after you upgrade the message will be gone, and the reference method will be available.

i think this code is correct but you should add this line of code in the end to show the plot

x=[[1,2,3],[4,5,6],[7,8,9]]
import numpy as np
import matplotlib.pyplot as plt

a=np.array(x)
print(a)
x = np.linspace(0, 10, 100)
print(x)
y= x ** 2
plt.plot(x,y)
plt.show()
Related