np.linspace() in python 1

np.linspace() in python

>>> import matplotlib.pyplot as plt
>>> N = 8
>>> y = np.zeros(N)
>>> x1 = np.linspace(0, 10, N, endpoint=True)
>>> x2 = np.linspace(0, 10, N, endpoint=False)
>>> plt.plot(x1, y, 'o')
[]
>>> plt.plot(x2, y + 0.5, 'o')
[]
>>> plt.ylim([-0.5, 1])
(-0.5, 1)
>>> plt.show()

Here is what the above code is Doing:
1. We import the matplotlib.pyplot module and rename it to plt.
2. We create an array of 8 zeros.
3. We create two arrays of 8 numbers, x1 and x2, using the linspace() function.
4. We plot x1 against y, and x2 against y + 0.5.
5. We set the y-axis limits to -0.5 to 1.
6. We show the plot.

Similar Posts