Line Chart


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 matplotlib, seaborn or plotly. This kind of basic chart type can also be learned in this online course.

⏱ Quick start

Making a simple line chart with matplotlib is pretty straightforward thanks to the plot() function.

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)

Matplotlib logoLine chart with Matplotlib

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). A common need is to build a dual Y axis line chart, but be mindful of the caveats that go with it.

Matplotlib logoLine chart with several groups (Matplotlib)

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.

Matplotlib logoFrom 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!

Contact

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Timeseries with python

Timeseries

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D