FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/date_demo_convert.py at transforms · gitj/matplotlib · GitHub
gitj
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
date_demo_convert.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (25 loc) · 1013 Bytes
Breadcrumbs
matplotlib
/
examples
/
date_demo_convert.py
Copy path
File metadata and controls
34 lines (25 loc) · 1013 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import
datetime
from
matplotlib
.
pyplot
import
figure
,
show
from
matplotlib
.
dates
import
DayLocator
,
HourLocator
,
DateFormatter
,
drange
from
numpy
import
arange
date1
=
datetime
.
datetime
(
2000
,
3
,
2
)
date2
=
datetime
.
datetime
(
2000
,
3
,
6
)
delta
=
datetime
.
timedelta
(
hours
=
6
)
dates
=
drange
(
date1
,
date2
,
delta
)
y
=
arange
(
len
(
dates
)
*
1.0
)
fig
=
figure
()
ax
=
fig
.
add_subplot
(
111
)
ax
.
plot_date
(
dates
,
y
*
y
)
# this is superfluous, since the autoscaler should get it right, but
# use date2num and num2date to to convert between dates and floats if
# you want; both date2num and num2date convert an instance or sequence
ax
.
set_xlim
(
dates
[
0
],
dates
[
-
1
] )
# The hour locator takes the hour or sequence of hours you want to
# tick, not the base multiple
ax
.
xaxis
.
set_major_locator
(
DayLocator
() )
ax
.
xaxis
.
set_minor_locator
(
HourLocator
(
arange
(
0
,
25
,
6
)) )
ax
.
xaxis
.
set_major_formatter
(
DateFormatter
(
'%Y-%m-%d'
) )
ax
.
fmt_xdata
=
DateFormatter
(
'%Y-%m-%d %H:%M:%S'
)
fig
.
autofmt_xdate
()
show
()
Back
|
FazBrowse Home
|
New Git URL