Plotting Line Charts
To see how easy it is to use matplotlib, let's plot a line chart using Jupyter Notebook. Here is a code snippet that plots a line chart:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(
[1,2,3,4,5,6,7,8,9,10],
[2,4.5,1,2,3.5,2,1,2,3,2]
)
Figure 4.1 shows the line chart plotted.
The first statement tells matplotlib to display the output of the plotting commands in line within front‐ends likes Jupyter Notebook. In short, it means display the chart within the same page as your Jupyter Notebook:
%matplotlib inline
To use matplotlib, you import the pyplot
module and name it plt
(its commonly used alias):
import matplotlib.pyplot as plt
To plot a line chart, you use the plot()
function from the pyplot
module, supplying it with two arguments as follows:
- A list of values representing the x‐axis
- A list of values representing the y‐axis
[1,2,3,4,5,6,7,8,9,10],
[2,4.5,1...