19
19
import matplotlib .ticker as ticker
20
20
21
21
locators = [
22
+ # locator as str, xmax, fmt
22
23
('AutoDateLocator(maxticks=8)' , '2003-02-01' , '%Y-%m' ),
23
24
('YearLocator(month=4)' , '2003-02-01' , '%Y-%m' ),
24
- ('MonthLocator(bymonth=[4,8, 12])' , '2003-02-01' , '%Y-%m' ),
25
+ ('MonthLocator(bymonth=[4, 8, 12])' , '2003-02-01' , '%Y-%m' ),
25
26
('DayLocator(interval=180)' , '2003-02-01' , '%Y-%m-%d' ),
26
27
('WeekdayLocator(byweekday=SU, interval=4)' , '2000-07-01' , '%a %Y-%m-%d' ),
27
- ('HourLocator(byhour=range(0,24,6))' , '2000-02-04' , '%H h' ),
28
+ ('HourLocator(byhour=range(0, 24, 6))' , '2000-02-04' , '%H h' ),
28
29
('MinuteLocator(interval=15)' , '2000-02-01 02:00' , '%H:%M' ),
29
- ('SecondLocator(bysecond=(0,30))' , '2000-02-01 00:02' , '%H:%M:%S' ),
30
+ ('SecondLocator(bysecond=(0, 30))' , '2000-02-01 00:02' , '%H:%M:%S' ),
30
31
('MicrosecondLocator(interval=1000)' , '2000-02-01 00:00:00.005' , '%S.%f' ),
31
- ('RRuleLocator(rrulewrapper(freq=MONTHLY, \n byweekday=(MO, TU, WE, TH,' +
32
- ' FR), bysetpos=-1))' , '2000-07-01' , '%Y-%m-%d' )
32
+ ('RRuleLocator(rrulewrapper(freq=MONTHLY, \n byweekday=(MO, TU, WE, TH, FR), '
33
+ 'bysetpos=-1))' , '2000-07-01' , '%Y-%m-%d' ),
33
34
]
34
35
35
36
formatters = [
36
- ( 'AutoDateFormatter(ax.xaxis.get_major_locator())' ) ,
37
- ( 'ConciseDateFormatter(ax.xaxis.get_major_locator())' ) ,
38
- ( 'DateFormatter("%b %Y")' )
37
+ 'AutoDateFormatter(ax.xaxis.get_major_locator())' ,
38
+ 'ConciseDateFormatter(ax.xaxis.get_major_locator())' ,
39
+ 'DateFormatter("%b %Y")' ,
39
40
]
40
41
41
42
42
43
def plot_axis (ax , locator = None , xmax = '2002-02-01' , fmt = None , formatter = None ):
43
44
"""Set up common parameters for the Axes in the example."""
44
- ax .spines .right .set_visible (False )
45
- ax .spines .left .set_visible (False )
46
- ax .spines .top .set_visible (False )
45
+ ax .spines [['left' , 'right' , 'top' ]].set_visible (False )
47
46
ax .yaxis .set_major_locator (ticker .NullLocator ())
48
47
ax .tick_params (which = 'major' , width = 1.00 , length = 5 )
49
48
ax .tick_params (which = 'minor' , width = 0.75 , length = 2.5 )
@@ -57,17 +56,17 @@ def plot_axis(ax, locator=None, xmax='2002-02-01', fmt=None, formatter=None):
57
56
fontsize = 14 , fontname = 'Monospace' , color = 'tab:blue' )
58
57
59
58
60
- fig , ax = plt .subplots (len (locators ), 1 , figsize = (8 , len (locators ) * .8 ),
61
- layout = 'constrained' )
59
+ fig , axs = plt .subplots (len (locators ), 1 , figsize = (8 , len (locators ) * .8 ),
60
+ layout = 'constrained' )
62
61
fig .suptitle ('Date Locators' )
63
- for i , loc in enumerate ( locators ):
64
- plot_axis (ax [ i ], * loc )
62
+ for ax , ( locator , xmax , fmt ) in zip ( axs , locators ):
63
+ plot_axis (ax , locator , xmax , fmt )
65
64
66
- fig , ax = plt .subplots (len (formatters ), 1 , figsize = (8 , len (formatters ) * .8 ),
67
- layout = 'constrained' )
65
+ fig , axs = plt .subplots (len (formatters ), 1 , figsize = (8 , len (formatters ) * .8 ),
66
+ layout = 'constrained' )
68
67
fig .suptitle ('Date Formatters' )
69
- for i , fmt in enumerate ( formatters ):
70
- plot_axis (ax [ i ] , formatter = fmt )
68
+ for ax , fmt in zip ( axs , formatters ):
69
+ plot_axis (ax , formatter = fmt )
71
70
72
71
73
72
# %%
0 commit comments