How to Make Line Charts in Python, with Pandas and Matplotlib
The chart type can be used to show patterns over time and relationships between variables. This is a comprehensive introduction to making them using two common libraries.
There are a number of charting libraries and tools for Python, but the basic, original built-in library is matplotlib. Many of the other Python data libraries that support charts (such as seaborn and pandas) call matplotlib functions “under the hood” and accept the same customization arguments and keywords. If you search for how to make a chart type in Python, chances are you will run into matplotlib code, so it’s a good idea to know a bit about it.
Because pandas is the default “data manipulation” library in Python, in this tutorial we’ll start from simple line chart displays with pandas, and then move on to customizing our charts with lower level matplotlib controls.
To access this full tutorial and download the source code you must be a member. (If you are already a member, log in here.)
Get instant access to this tutorial and over a hundred more, plus courses, guides, and additional resources.
You'll get unlimited access to hundreds of hours worth of step-by-step visualization courses and tutorials for insight and presentation — all while supporting an independent site. Source code and data is included so that you can more easily apply what you learn in your own work.
The tutorials are very helpful to move from "Oooo, cool!" to how to actually DO the cool.
Members also recieve a weekly newsletter, The Process. Keep up-to-date on visualization tools, the rules, and the guidelines and how they all work together in practice.
See samples of everything you gain access to:
More Tutorials See All →
How to Draw Maps with Hatching Lines in R
Fill areas with varying line density to give more or less visual attention. With geographic maps, the technique is especially useful to adjust for population density.
How to Make Ternary Plots in R, with ggplot2
When you want to compare between three parts of your data, ternary plots might be a good option. Here is how to make them.
A Course for Visualization in R, Taking You From Beginner to Advanced
Where to start? What to learn next? Here’s a course to help take you from beginner to advanced.