Calendar Heat Map#
Goal
Visualize daily electricity consumption as a calendar heatmap to identify patterns and anomalies over time.
Data Basis
The dataset flatElectricity.csv contains cumulative electricity meter readings at 15-minute intervals for multiple flats. We use the column FlatA_Ele, convert cumulative readings to consumption by computing differences and sum them per day. Days with missing readings stay empty in the calendar.
Data Preparation#
import pandas as pd
url = "https://raw.githubusercontent.com/retomarek/edap/main/edap/sampleData/flatElectricity.csv"
raw = pd.read_csv(url, sep=";")
# Parse timestamp and set as index
raw["time"] = pd.to_datetime(raw["time"])
raw = raw.set_index("time")
# Consumption per 15 minutes from the cumulative meter readings (kWh)
consumption = raw["FlatA_Ele"].diff()
# Daily sums of complete days only (all 96 quarter-hours have a reading):
# without min_count, days with missing data would show up as low or zero
# consumption
daily = consumption.resample("D").sum(min_count=96).dropna()
# Build clean 2-column DataFrame [timestamp, value]
df = daily.reset_index()
df.columns = ["timestamp", "value"]
df.head()
| timestamp | value | |
|---|---|---|
| 0 | 2018-12-01 | 14.324 |
| 1 | 2018-12-02 | 14.141 |
| 2 | 2018-12-03 | 12.444 |
| 3 | 2018-12-04 | 7.954 |
| 4 | 2018-12-05 | 5.732 |
Visualization#
from pyedautils.plots import plot_heatmap_calendar
fig = plot_heatmap_calendar(df, title="Electricity — Calendar Heat Map",
ylab="Electricity [kWh/d]")
fig.show()
Customization
The plot_heatmap_calendar function accepts a colorscale parameter to change the color palette of the heatmap. For example:
fig = plot_heatmap_calendar(df, title="Electricity — Calendar Heat Map", ylab="Electricity [kWh/d]", colorscale="Viridis")