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.13/Matplotlib-3.10.9
axis=x
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14. Cross second boundary
15. Cross minute boundary
16. Cross hour boundary
17. Cross day boundary
18. Cross month boundary
19.
20. Cross second boundary
21. Cross minute boundary
22. Cross hour boundary
23. Cross day boundary
24. Cross month boundary
25.
26. Cross second boundary
27. Cross minute boundary
28. Cross hour boundary
29. Cross day boundary
30. Cross month boundary
31. (font size change: -0.8 pt)
32. Cross second boundary (font size change: -0.8 pt)
33. Cross minute boundary (font size change: -0.8 pt)
34. Cross hour boundary (font size change: -0.8 pt)
35. Cross day boundary (font size change: -0.8 pt)
36. Cross month boundary (font size change: -0.8 pt)
37. (font size change: -1.8 pt)
38. Cross second boundary (font size change: -1.8 pt)
39. Cross minute boundary (font size change: -1.8 pt)
40. Cross hour boundary (font size change: -1.8 pt)
41. Cross day boundary (font size change: -1.8 pt)
42. Cross month boundary (font size change: -1.9 pt)
43. (font size change: -2.8 pt)
44. Cross second boundary (font size change: -2.8 pt)
45. Cross minute boundary (font size change: -2.8 pt)
46. Cross hour boundary (font size change: -2.8 pt)
47. Cross day boundary (font size change: -2.8 pt)
48. Cross month boundary (font size change: -2.8 pt)
49.
50. Cross second boundary
51. Cross minute boundary
52. Cross hour boundary
53. Cross day boundary
54. Cross month boundary
55.
56. Cross second boundary
57. Cross minute boundary
58. Cross hour boundary
59. Cross day boundary
60. Cross month boundary
61.
62. Cross second boundary
63. Cross minute boundary
64. Cross hour boundary
65. Cross day boundary
66. Cross month boundary
67.
68. Cross second boundary (rule change: 1)
69. Cross minute boundary (rule change: 1)
70. Cross hour boundary (rule change: 1)
71. Cross day boundary (rule change: 1)
72. Cross month boundary (rule change: 1)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datetick-0.9.11.tar.gz.
File metadata
- Download URL: datetick-0.9.11.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
327e5e5c75b5103988cea6db4385b384b8ee8c7ecc84ee8e53f8df88ee76a656
|
|
| MD5 |
9c80b979bc743026f520795f336f6420
|
|
| BLAKE2b-256 |
f9db28c27141896094cf660893fa04b368a449882ea59e89f7a80089c079fa2d
|
File details
Details for the file datetick-0.9.11-py3-none-any.whl.
File metadata
- Download URL: datetick-0.9.11-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abb1d96befa51603b53f03978620a1a8a580cefad7cf79a55490634299d7cc94
|
|
| MD5 |
8cba7bca2c3f6cff61cd54531020c0fb
|
|
| BLAKE2b-256 |
c2fa9909e10d3e14368b0c698e0ff712ddafa3a00c840b49c169d1f8dd03e05f
|