Calendar Heatmaps with Python’s Calplot
A quick guide on plotting and customizing calendar heatmaps with Python
Few visualizations are so intuitive and insightful as calendar heatmaps are at presenting time series data. It could be because they combine two very familiar visualizations, color coding and calendars.
You probably know someone who has a planner or a calendar full of notes; some may use brighter colors to mark tasks requiring more attention, or maybe they color-code everything by category.
The concept of calendar heatmaps is very similar. We encode a variable with color and plot them in a calendar format to understand its relationship with time.
This tutorial will explore a convenient package called Calplot to draw our calendar heatmaps quickly.
Data preparation
We can start by loading our dataset into Pandas, ensuring the date field is in the correct format and set it as the data frame index.
import pandas as pd# kaggle.com/navinmundhra/daily-power-generation-in-india-20172020
df = pd.read_csv('data/dailyPowerGeneration.csv')
df['Date'] = pd.to_datetime(df.Date, yearfirst=True)
df.set_index('Date', inplace=True)df.head()