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))
  • Passing None as daily_label or hourly_label omits the respective daily overview or mean profile subplot.
fig = heatmapfigure(series, daily_label=None)
  • 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.2.tar.gz (8.9 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.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: heatmapts-0.1.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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.2.tar.gz
Algorithm Hash digest
SHA256 bb7a8f67ef4ae636b764205407e6087ff0199188827d07db07f0cba17b7aa1f6
MD5 6e98ca876f896f6529647d6c57df0835
BLAKE2b-256 a8f04d85700d10e611001960817a81842ff1d34cff7693e1ff210cdb875c9cea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: heatmapts-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7582c18a811495f7a93aa2308143f6c371d41109420e15c964726e07937604d6
MD5 b32e791410937db0bad913a7f2f3b69c
BLAKE2b-256 f1d9110878366c238a7fd3d04dfe0cfb2930b210704f625db22911b618806bf1

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