1818 WeekdayLocator , YearLocator , rrulewrapper )
1919import matplotlib .ticker as ticker
2020
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-
4221
4322def plot_axis (ax , locator = None , xmax = '2002-02-01' , fmt = None , formatter = None ):
4423 """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):
5534 ax .text (0.0 , 0.2 , locator or formatter , transform = ax .transAxes ,
5635 fontsize = 14 , fontname = 'Monospace' , color = 'tab:blue' )
5736
37+ # %%
38+ # :ref:`Date locators <date-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+ ]
5856
5957fig , axs = plt .subplots (len (locators ), 1 , figsize = (8 , len (locators ) * .8 ),
6058 layout = 'constrained' )
6159fig .suptitle ('Date Locators' )
6260for ax , (locator , xmax , fmt ) in zip (axs , locators ):
6361 plot_axis (ax , locator , xmax , fmt )
6462
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+
6573fig , axs = plt .subplots (len (formatters ), 1 , figsize = (8 , len (formatters ) * .8 ),
6674 layout = 'constrained' )
6775fig .suptitle ('Date Formatters' )
0 commit comments