5 Steps to Beautiful Line Charts in Python

How to use the full capabilities of to tell a more compelling story

Guillaume Weingertner
Towards Data Science
GDP Evolution over of the 5 richest countries — by Author

A few months back I wrote an article about bar charts and how you could make them clear, self-explanatory, and visually pleasing to the audience in order to tell a more compelling story (link below).

In this article I look into line charts instead, which have other specificities that are worth exploring.

Matplotlib makes it quick and easy to plot with off-the-shelf functions but the tuning steps take more effort.

I spent quite some time researching best practices to build compelling charts with Matplotlib, so you don’t have to.

The idea is to go from this…

… to that:

All , unless otherwise noted, are by the author.

To illustrate the methodology, I used a public containing countries’ GDP information over the past 50 years:

: World Bank national accounts data, and OECD National Accounts data .
License URL: https://datacatalog.worldbank.org/public-licenses#cc-by
License Type: CC BY-4.0

After importing the necessary packages to read the data and build our graphs, I simply filtered on the Top 20 countries of 2022:

import  as pd
import matplotlib.pyplot as plt
from datetime import timedelta

# Read the data
df = pd.read_csv('88a1e584-0a94-4e73-b650-749332831ef4_Data.csv', sep=',')
df.drop(['Series Name', 'Series Code', 'Country Code']…

Source link