I tried to draw a graph of sin, but I got an error. What's wrong?

Asked 1 years ago, Updated 1 years ago, 384 views

%matplotlib inline
import matplotlib.pyplot asplt

import numpy as np
X=np.linspace(0,2*np.pi)
y = np.sin(X)

plt.plot(x,y)
------------------------------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_26536\2280643985.py in<module>
      3 y = np.sin(X)
      4 
---->5plt.plot(x,y)

NameError: name 'x' is not defined

python

2023-01-03 14:16

1 Answers

It appears to be an error due to a case difference.Let's unify to one or the other.

Where X is capitalized:

X=np.linspace(0,2*np.pi)
y = np.sin(X)

x in lowercase:

plt.plot(x,y)


2023-01-03 17:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.