This blog is part of Matplotlib Series:
- Matplotlib Series 1: Bar chart
- Matplotlib Series 2: Line chart (this blog)
- Matplotlib Series 3: Pie chart
- Matplotlib Series 4: Scatter plot
- Matplotlib Series 5: Treemap
- Matplotlib Series 6: Venn diagram
- Matplotlib Series 7: Area chart
- Matplotlib Series 8: Radar chart
- Matplotlib Series 9: Word cloud
- Matplotlib Series 10: Lollipop plot
- Matplotlib Series 11: Histogram
A line chart or line graph is a type of chart which displays information as a series of data points called ‘markers’ connected by straight line segments. A line chart is often used to visualize a trend in data over intervals of time – a time series – thus the line is often drawn chronologically.
When to use it ?
- Track changes over time
- x-axis displays continuous variables
- Y-axis displays measurement
Suppose that the plot above describes the turnover(k euros) of ice-cream’s sales during one year. According to the plot, we can clearly find that the sales reach a peak in summer, then fall from autumn to winter, which is logical.
Line chart with multiple lines
When to use it ?
Compare different subjects during the same period.
As an extension of the first plot, the second one compares two-year turnover together. The peak for both year is in the summer, for year N, the peak is in August; however, the peak is reached in June in the year N-1, which is caused by the heatwave in June.
Add values’ label on the plot
We find that there is no parameter for add values’ labels by plt.plot(), but we can add them with text() function.
You can click here to check this example in jupyter notebook.
- Steve Johnson, “painting wallpaper”, www.pexels.com. [Online]. Available: https://www.pexels.com/photo/painting-wallpaper-1070527/