Just a few months again I wrote an article about bar charts and the way you would make them clear, self-explanatory, and visually pleasing to the viewers in an effort to inform a extra compelling story (hyperlink beneath).
On this article I look into line charts as an alternative, which produce other specificities which can be price exploring.
Matplotlib makes it fast and simple to plot knowledge with off-the-shelf capabilities however the high quality tuning steps take extra effort.
I spent fairly a while researching finest practices to construct compelling charts with Matplotlib, so that you don’t should.
The concept is to go from this…
… to that:
As an example the methodology, I used a public dataset containing international locations’ GDP info over the previous 50 years:
Supply: World Financial institution nationwide accounts knowledge, and OECD Nationwide Accounts knowledge recordsdata.
License URL: https://datacatalog.worldbank.org/public-licenses#cc-by
License Sort: CC BY-4.0
After importing the required packages to learn the info and construct our graphs, I merely filtered on the Prime 20 international locations of 2022:
import pandas as pd
import matplotlib.pyplot as plt
from datetime import timedelta
# Learn the info
df = pd.read_csv('88a1e584-0a94-4e73-b650-749332831ef4_Data.csv', sep=',')
df.drop(['Series Name', 'Series Code', 'Country Code'], axis=1, inplace=True)
df = df.dropna(subset=['Country Name'])
# Filter on the Prime 20…