September 2019
Intermediate to advanced
420 pages
10h 29m
English
Without further ado, let's create our first plot.
Let's say that we want to produce a simple line plot of the sine function, sin(x). We want the function to be evaluated at all points on the x axis where 0 < x < 10. We will use NumPy's linspace function to create a linear spacing on the x axis, from x values 0 to 10, and a total of 100 sampling points:
In [3]: import numpy as npIn [4]: x = np.linspace(0, 10, 100)
We can evaluate the sin function at all points, x, using NumPy's sin function, and visualize the result by calling the plot function of plt:
In [5]: plt.plot(x, np.sin(x))
Did you try it yourself? What happened? Did anything show up?
The thing is, depending on where you are running this script, you might not ...
Read now
Unlock full access