File: date.py

package info (click to toggle)
mplcursors 0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 1,915; makefile: 14; sh: 9
file content (23 lines) | stat: -rw-r--r-- 500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Datetime data
=============

mplcursors correctly formats datetime data.
"""

import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import mplcursors

t = mdates.drange(dt.datetime(2014, 1, 15), dt.datetime(2014, 2, 27),
                  dt.timedelta(hours=2))
y = np.sin(t)
fig, ax = plt.subplots()
ax.plot(mdates.num2date(t), y, "-")

# Note that mplcursors will automatically display the x-values as dates.
mplcursors.cursor()

plt.show()