Skip to main content

The classical time series heatmap plot extended with a mean profile and daily average and peaks.

Project description

The classical time series heatmap plot extended with a mean profile and daily average and peaks. This type of visualization is very informative when showing large amounts of time series data. While I mostly use it for energy data, it can easily be adapted for any other time series. The figure works best for data with a range of a few months to a few years and a resolution of a few minutes to a few hours.

Sample plot created with HeatmapTS

Installation

The package is available on PyPI:

pip install heatmapts

Alternatively, you can install it from GitHub:

pip install git+https://github.com/markus-kreft/heatmapts.git

or simply clone this repository and work in the local directory.

Usage

The module provides the heatmapfigure function that takes a pandas Series with a timezone-aware DatetimeIndex with frequency.

This example show how to load and prepare data from a csv file in the necessary way. This needs to be adapted depending on the format of the data at hand.

from heatmapts import heatmapfigure

# Read data
df = pd.read_csv('data.csv', index_col='Timestamp')
# Convert index to datetime and set timezone
df.index = pd.to_datetime(df.index, format='%Y-%m-%d %H:%M:%S').tz_convert('Europe/Zurich')
# Resample to 15 frequency
df = df.asfreq("15min", fill_value=pd.NA)
# Take data column and convert energy to power
series = df['Value'] * 4

fig = heatmapfigure(series, rasterized=True)
fig.savefig("plot.pdf")

Customization

The figure is designed for easy customization.

  • Any additional keyword arguments are passed to pcolormesh, which is especially convenient for using a different colormap or norm or to use rasterization.
  • Passing a tuple of latitude and longitude coordinates will add sunrise and sunset times to the plot.
fig = heatmapfigure(series, annotate_suntimes=(52.37, 4.90))
  • The returned figure is subclassed from matplotlib.figure.Figure and features additional attributes for the heatmap, colorbar, daily and hourly axes. These can be modified as any other matplotlib axis.
fig.ax_heatmap.xaxis.set_major_locator(mdates.YearLocator())
fig.ax_heatmap.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
  • The figure uses its own rcParams for styling. You can modify or overwrite the parameters on a class level. When setting an empty rcParams dictionary, the current parameters from matplotlib (e.g., as determined by matplotlibrc) will be used.
from heatmapts import HeatmapFigure
# Customize rc parameters
HeatmapFigure.rc_params["font.family"] = "serif"
HeatmapFigure.rc_params["font.size"] = 5

# Set empty rc parameters to use those from matplotlib
HeatmapFigure.rc_params = {}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

heatmapts-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

heatmapts-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file heatmapts-0.1.0.tar.gz.

File metadata

  • Download URL: heatmapts-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for heatmapts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ea3ebe0b6d3fff9530653bb90915a620eeb341481a820873e10c8be7f2720dc
MD5 03d091de424f4296f6fea87a61b65ea4
BLAKE2b-256 74717342697325f2c7e8c6e843abd3011ebe82ed18b3049f173d3244ccafdee8

See more details on using hashes here.

File details

Details for the file heatmapts-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: heatmapts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for heatmapts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a47811e968ec13ea4e009cf1e573f75db72f3709af1ccdc753d90337c90de58
MD5 517fa7eb7c04f6c34c0297ed402f8a54
BLAKE2b-256 329b7e037e38da1ccea96b0bcf7a51a940968c156e06b56924a86cf5dfec0142

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page