First we import the modules matplotlib
for plotting and numpy
for numerical array manipulation:
In [30]:
from matplotlib import pyplot as plt
import numpy as np
Next we set the variable xs
to be an array of 100 equally spaced points in the interval [-1,1]:
In [31]:
xs = np.linspace(-2, 2, num=100)
print(xs)
Now we set the array ys
to be the elementwise square of xs
:
In [32]:
ys = xs*xs
print(ys)
Now we plot the result using matplotlib
:
In [33]:
plt.plot(xs, ys)
plt.xlabel('x')
plt.ylabel('y')
plt.title('plot of y = x**2')
plt.show()
For more information see the numpy webpage and the matplotlib webpage
In [ ]: