Skip to main content

datetick

Sensible date/time tick labels for Matplotlib

Motivation

Matplotlib's default date/time tick labels are often poor, and adjusting them requires using locators and formatters on an ad-hoc basis. A method or package for handling arbitrary time ranges does not exist.

In addition, the interfaces for locators and formatters complex and non-intuitive and require study and experimentation (e.g., [1], [2], [3], [4]. Tilting labels is an often-suggested solution, but this should not be needed.

datetick() contains logic for locators and formatters that apply to plots with arbitrary time ranges. One only needs to add the command datetick() after the usual plt.plot(...) command to have sensible and useable time tick labels. The primary configuration is a set of rules that account for the time range and an adjustable minimum gap between tick labels.

To prevent overlap and enforce a minimum gap, the font size is automatically reduced to a chosen minimum value. Then the number of ticks are reduced based on rules in rules.json.

Usage

import datetime as dt
import matplotlib.pyplot as plt
from datetick import datetick

dt1 = dt.datetime(2011, 1, 2)
dt2 = dt1 + dt.timedelta(days=1, hours=1, minutes=1)

plt.plot([dt1, dt2], [0.0,1.0])
datetick()
plt.show()
# or
# datetick('x') (use 'y' if y variable is datetime-like)
# or
# datetick('x', axes=plt.gca())
# or
# fig, axes = plt.subplots(2)
# plt.plot([dt1, dt2], [0.0, 1.0])
# datetick('x', axes=axes[0])

Comparison to default Matplotlib

Python-3.12/Matplotlib-3.8.4

axis=x

1.

test/visual_test/latest/20030901000000-20031201000000-6.4in_v1.svg

Download files

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

Source Distribution

datetick-0.9.13.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

datetick-0.9.13-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file datetick-0.9.13.tar.gz.

File metadata

  • Download URL: datetick-0.9.13.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for datetick-0.9.13.tar.gz
Algorithm Hash digest
SHA256 770337aca60efa439da8fb73e4fd9192851e7bd22a429776b73d57e4c97bda25
MD5 e4e9517ebcad6bf0888724a00e5ba92a
BLAKE2b-256 3bc3a0fb98e5c1b0258015b3522ad6d68db3c795cd15e13e63b7d3bfd822469b

See more details on using hashes here.

File details

Details for the file datetick-0.9.13-py3-none-any.whl.

File metadata

  • Download URL: datetick-0.9.13-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for datetick-0.9.13-py3-none-any.whl
Algorithm Hash digest
SHA256 234019cab2bb83767ffb6b81150d9d507ba9efb562109192220fb1c76592a785
MD5 ebb1e60ff4d76e263d84586a881dd96b
BLAKE2b-256 7cd83b2ebf01e7591d9fa15dd031c03f09e87dfb52c32d711aac496666a87056

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.15

2 files

0.9.14

2 files

This release

0.9.13 This release

2 files

0.9.12

2 files

0.9.11

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.1

2 files

0.9.0

2 files

Supported by

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