A line chart displays the evolution of one or several numeric variables. It is one of the most common chart type, so it can be build using any python viz library, like
⏱ Quick start
Making a simple line chart with
matplotlib is pretty straightforward thanks to the
If you provide only a series of values, it will consider that these values are ordered and will use values from 1 to n to create the X axis.🔥
For more control on the chart, see the dedicated section below.
# libraries import matplotlib.pyplot as plt import numpy as np # create data values=np.cumsum(np.random.randn(1000,1)) # use the plot function plt.plot(values)
Line chart with
Matplotlib is a great fit to build line charts thanks to its
plot() function. The first chart of this section explains how to use
plot() from any kind of data input format. The next one goes deep into chart customization (line width, color aspect and more).
Line chart with several groups (
A line chart with multiple groups allows to show the evolution of several items on the same figure. It is powerful but can quickly turn into a spaghetti chart: when too many lines are displayed they get hard to read. The examples below explain how to build one, and what are the alternative to show your data a better way.
From the web
The web is full of astonishing charts made by awesome bloggers, (often using R). The Python graph gallery tries to display (or translate from R) some of the best creations and explain how their source code works. If you want to display your work here, please drop me a word or even better, submit a Pull Request!