Skip to main content

Sensible date tick locator for matplotlib

Project description

datetick

Sensible numeric time and date tick labels for Matplotlib

Motivation

Matplotlib's default time tick labels are often poor, and adjusting them requires using locators and formatters on an ad-hoc basis. In addition, the interfaces for locators and formatters complex and non-intuitive and require study and experimentation.

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 Matplotlib plt.plot(...) command to have sensible and useable time tick labels.

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 a time)
# 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.13 / Matplotlib-3.10.9

dir=x

test/visual_test/latest/20010101000000-20010102230000-x.svg

test/visual_test/latest/20010101000000-20010102230000-x_v2.svg

test/visual_test/latest/20010101000000-20010102230000-x_v3.svg

test/visual_test/latest/20001231170000-20010102190000-x.svg

test/visual_test/latest/20001231170000-20010102190000-x_v2.svg

test/visual_test/latest/20010101000000-20010101000001-x.svg

test/visual_test/latest/20010101000000-20010101000002-x.svg

test/visual_test/latest/20010101000000-20010101000003-x.svg

test/visual_test/latest/20010101000000-20010101000004-x.svg

test/visual_test/latest/20010101235958-20010102000002-x.svg

test/visual_test/latest/20010101000000-20010101000005-x.svg

test/visual_test/latest/20010101000000-20010101000006-x.svg

test/visual_test/latest/20010101000000-20010101000007-x.svg

test/visual_test/latest/20010101000000-20010101000009-x.svg

test/visual_test/latest/20010101235958-20010102000005-x.svg

test/visual_test/latest/20010101235959-20010102000005-x.svg

test/visual_test/latest/20010101005958-20010101010005-x.svg

test/visual_test/latest/20010101005958-20010101010007-x.svg

test/visual_test/latest/20010101005958-20010101010003-x.svg

test/visual_test/latest/20010101235956-20010102000010-x.svg

test/visual_test/latest/20010101235958-20010102000010-x.svg

test/visual_test/latest/20010101005956-20010101010010-x.svg

test/visual_test/latest/20010101005956-20010101010015-x.svg

test/visual_test/latest/20010101005956-20010101010006-x.svg

test/visual_test/latest/20010101000000-20010101000021-x.svg

test/visual_test/latest/20010101000000-20010101060000-x.svg

test/visual_test/latest/20010101000000-20010101090000-x.svg

test/visual_test/latest/20010101000000-20010101110000-x.svg

test/visual_test/latest/20010101000000-20010101110000-x_v2.svg

test/visual_test/latest/20010101005958-20010101010028-x.svg

test/visual_test/latest/20010101000058-20010101000118-x.svg

test/visual_test/latest/20010101000000-20010101180000-x.svg

test/visual_test/latest/20010101000000-20010101120000-x.svg

test/visual_test/latest/20010101000000-20010101230000-x.svg

test/visual_test/latest/20010101020000-20010102010000-x.svg

test/visual_test/latest/20010101000000-20010102010000-x.svg

test/visual_test/latest/20010101060000-20010102070000-x.svg

test/visual_test/latest/20010101003000-20010102010000-x.svg

test/visual_test/latest/20010101000000-20010103000000-x.svg

test/visual_test/latest/20010101000000-20010103123000-x.svg

test/visual_test/latest/20010101000000-20010103235959-x.svg

test/visual_test/latest/20010101000000-20010105000000-x.svg

test/visual_test/latest/20010101000000-20010105000000-x_v2.svg

test/visual_test/latest/20010130000000-20010201230000-x.svg

test/visual_test/latest/20011230000000-20020101230000-x.svg

test/visual_test/latest/20010101000000-20010109000000-x.svg

test/visual_test/latest/20010101000000-20010116230000-x.svg

test/visual_test/latest/20010130000000-20010204230000-x.svg

test/visual_test/latest/20011230000000-20020104230000-x.svg

test/visual_test/latest/20010101000000-20010131000000-x.svg

test/visual_test/latest/20010101000000-20010116230000-x_v2.svg

test/visual_test/latest/20010130000000-20010215230000-x.svg

test/visual_test/latest/20011230000000-20010115230000-x.svg

test/visual_test/latest/20010101000000-20010202000000-x.svg

test/visual_test/latest/20010101000000-20010227230000-x.svg

test/visual_test/latest/20010115000000-20010216230000-x.svg

test/visual_test/latest/20011231000000-20020226230000-x.svg

test/visual_test/latest/20010101000000-20010502000000-x.svg

test/visual_test/latest/20010101000000-20010227230000-x_v2.svg

test/visual_test/latest/20011231000000-20020226230000-x_v2.svg

test/visual_test/latest/20010101000000-20010702000000-x.svg

test/visual_test/latest/20010101000000-20011231000000-x.svg

test/visual_test/latest/20010212000000-20020131000000-x.svg

test/visual_test/latest/20010101000000-20020103000000-x.svg

test/visual_test/latest/20010101000000-20021231000000-x.svg

test/visual_test/latest/20010401000000-20020430000000-x.svg

test/visual_test/latest/20011001000000-20031004000000-x.svg

test/visual_test/latest/20010101000000-20081231000000-x.svg

test/visual_test/latest/20010101000000-20030104000000-x.svg

test/visual_test/latest/20010101000000-20090104000000-x.svg

test/visual_test/latest/20010101000000-20120104000000-x.svg

test/visual_test/latest/20000101000000-20170104000000-x.svg

test/visual_test/latest/20010101000000-20180104000000-x.svg

test/visual_test/latest/20020101000000-20190104000000-x.svg

test/visual_test/latest/20030101000000-20200104000000-x.svg

test/visual_test/latest/20040101000000-20300104000000-x.svg

test/visual_test/latest/19500101000000-20120104000000-x.svg

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

datetick-0.9.7.tar.gz (15.2 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.7-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for datetick-0.9.7.tar.gz
Algorithm Hash digest
SHA256 ae441727bac04a018b35c188b1aa6b4bee48e1ff8d842c2e778df6215e6d4b06
MD5 f76e03d371ac067575f0f60d536b47d7
BLAKE2b-256 473212ddeebc54a55d3a72193ff88ac40b7e65f9d9c41d561c7647b025a660a6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for datetick-0.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c55fea69a56659cee2f2b95cb65d8fd19b6fd6af4e1301639d8f7ced5c38479c
MD5 081507246e688f5d7a0ae08ad3d8645f
BLAKE2b-256 e105a8b15e1ab8a5eb7f8c660fa5fee45f9ee04ce88f141b31e50a18dec61dca

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