18
18
WeekdayLocator , YearLocator , rrulewrapper )
19
19
import matplotlib .ticker as ticker
20
20
21
- locators = [
22
- # locator as str, xmax, fmt
23
- ('AutoDateLocator(maxticks=8)' , '2003-02-01' , '%Y-%m' ),
24
- ('YearLocator(month=4)' , '2003-02-01' , '%Y-%m' ),
25
- ('MonthLocator(bymonth=[4, 8, 12])' , '2003-02-01' , '%Y-%m' ),
26
- ('DayLocator(interval=180)' , '2003-02-01' , '%Y-%m-%d' ),
27
- ('WeekdayLocator(byweekday=SU, interval=4)' , '2000-07-01' , '%a %Y-%m-%d' ),
28
- ('HourLocator(byhour=range(0, 24, 6))' , '2000-02-04' , '%H h' ),
29
- ('MinuteLocator(interval=15)' , '2000-02-01 02:00' , '%H:%M' ),
30
- ('SecondLocator(bysecond=(0, 30))' , '2000-02-01 00:02' , '%H:%M:%S' ),
31
- ('MicrosecondLocator(interval=1000)' , '2000-02-01 00:00:00.005' , '%S.%f' ),
32
- ('RRuleLocator(rrulewrapper(freq=MONTHLY, \n byweekday=(MO, TU, WE, TH, FR), '
33
- 'bysetpos=-1))' , '2000-07-01' , '%Y-%m-%d' ),
34
- ]
35
-
36
- formatters = [
37
- 'AutoDateFormatter(ax.xaxis.get_major_locator())' ,
38
- 'ConciseDateFormatter(ax.xaxis.get_major_locator())' ,
39
- 'DateFormatter("%b %Y")' ,
40
- ]
41
-
42
21
43
22
def plot_axis (ax , locator = None , xmax = '2002-02-01' , fmt = None , formatter = None ):
44
23
"""Set up common parameters for the Axes in the example."""
@@ -55,13 +34,42 @@ def plot_axis(ax, locator=None, xmax='2002-02-01', fmt=None, formatter=None):
55
34
ax .text (0.0 , 0.2 , locator or formatter , transform = ax .transAxes ,
56
35
fontsize = 14 , fontname = 'Monospace' , color = 'tab:blue' )
57
36
37
+ # %%
38
+ # :ref:`Date locators <date-tickers>` (also known as tickers)
39
+ # -----------------------------------------------------------
40
+
41
+
42
+ locators = [
43
+ # locator as str, xmax, fmt
44
+ ('AutoDateLocator(maxticks=8)' , '2003-02-01' , '%Y-%m' ),
45
+ ('YearLocator(month=4)' , '2003-02-01' , '%Y-%m' ),
46
+ ('MonthLocator(bymonth=[4, 8, 12])' , '2003-02-01' , '%Y-%m' ),
47
+ ('DayLocator(interval=180)' , '2003-02-01' , '%Y-%m-%d' ),
48
+ ('WeekdayLocator(byweekday=SU, interval=4)' , '2000-07-01' , '%a %Y-%m-%d' ),
49
+ ('HourLocator(byhour=range(0, 24, 6))' , '2000-02-04' , '%H h' ),
50
+ ('MinuteLocator(interval=15)' , '2000-02-01 02:00' , '%H:%M' ),
51
+ ('SecondLocator(bysecond=(0, 30))' , '2000-02-01 00:02' , '%H:%M:%S' ),
52
+ ('MicrosecondLocator(interval=1000)' , '2000-02-01 00:00:00.005' , '%S.%f' ),
53
+ ('RRuleLocator(rrulewrapper(freq=MONTHLY, \n byweekday=(MO, TU, WE, TH, FR), '
54
+ 'bysetpos=-1))' , '2000-07-01' , '%Y-%m-%d' ),
55
+ ]
58
56
59
57
fig , axs = plt .subplots (len (locators ), 1 , figsize = (8 , len (locators ) * .8 ),
60
58
layout = 'constrained' )
61
59
fig .suptitle ('Date Locators' )
62
60
for ax , (locator , xmax , fmt ) in zip (axs , locators ):
63
61
plot_axis (ax , locator , xmax , fmt )
64
62
63
+ # %%
64
+ # :ref:`date-formatters`
65
+ # ----------------------
66
+
67
+ formatters = [
68
+ 'AutoDateFormatter(ax.xaxis.get_major_locator())' ,
69
+ 'ConciseDateFormatter(ax.xaxis.get_major_locator())' ,
70
+ 'DateFormatter("%b %Y")' ,
71
+ ]
72
+
65
73
fig , axs = plt .subplots (len (formatters ), 1 , figsize = (8 , len (formatters ) * .8 ),
66
74
layout = 'constrained' )
67
75
fig .suptitle ('Date Formatters' )
0 commit comments