1919import matplotlib .ticker as ticker
2020
2121locators = [
22+ # locator as str, xmax, fmt
2223 ('AutoDateLocator(maxticks=8)' , '2003-02-01' , '%Y-%m' ),
2324 ('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' ),
2526 ('DayLocator(interval=180)' , '2003-02-01' , '%Y-%m-%d' ),
2627 ('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' ),
2829 ('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' ),
3031 ('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' ),
3334]
3435
3536formatters = [
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")' ,
3940]
4041
4142
4243def plot_axis (ax , locator = None , xmax = '2002-02-01' , fmt = None , formatter = None ):
4344 """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 )
4746 ax .yaxis .set_major_locator (ticker .NullLocator ())
4847 ax .tick_params (which = 'major' , width = 1.00 , length = 5 )
4948 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):
5756 fontsize = 14 , fontname = 'Monospace' , color = 'tab:blue' )
5857
5958
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' )
6261fig .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 )
6564
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' )
6867fig .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 )
7170
7271
7372# %%
0 commit comments