Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98f9043

Browse files
committed
ENH: enable_deconflict property & thread through Locator __init__
1 parent 600cdd2 commit 98f9043

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

lib/matplotlib/dates.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,11 @@ class DateLocator(ticker.Locator):
11611161
"""
11621162
hms0d = {'byhour': 0, 'byminute': 0, 'bysecond': 0}
11631163

1164-
def __init__(self, tz=None):
1164+
def __init__(self, tz=None, **kwargs):
11651165
"""
11661166
*tz* is a :class:`tzinfo` instance.
11671167
"""
1168+
super().__init__(**kwargs)
11681169
if tz is None:
11691170
tz = _get_rc_timezone()
11701171
self.tz = tz
@@ -1235,8 +1236,8 @@ def nonsingular(self, vmin, vmax):
12351236
class RRuleLocator(DateLocator):
12361237
# use the dateutil rrule instance
12371238

1238-
def __init__(self, o, tz=None):
1239-
DateLocator.__init__(self, tz)
1239+
def __init__(self, o, tz=None, **kwargs):
1240+
super().__init__(tz, **kwargs)
12401241
self.rule = o
12411242

12421243
def __call__(self):
@@ -1344,7 +1345,7 @@ class AutoDateLocator(DateLocator):
13441345
locations.
13451346
"""
13461347
def __init__(self, tz=None, minticks=5, maxticks=None,
1347-
interval_multiples=True):
1348+
interval_multiples=True, **kwargs):
13481349
"""
13491350
*minticks* is the minimum number of ticks desired, which is used to
13501351
select the type of ticking (yearly, monthly, etc.).
@@ -1391,7 +1392,7 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
13911392
locator = AutoDateLocator()
13921393
locator.intervald[HOURLY] = [3] # only show every 3 hours
13931394
"""
1394-
DateLocator.__init__(self, tz)
1395+
super().__init__(tz, **kwargs)
13951396
self._locator = YearLocator(tz=tz)
13961397
self._freq = YEARLY
13971398
self._freqs = [YEARLY, MONTHLY, DAILY, HOURLY, MINUTELY,
@@ -1586,12 +1587,12 @@ class YearLocator(DateLocator):
15861587
# Tick every 5 years on July 4th
15871588
locator = YearLocator(5, month=7, day=4)
15881589
"""
1589-
def __init__(self, base=1, month=1, day=1, tz=None):
1590+
def __init__(self, base=1, month=1, day=1, tz=None, **kwargs):
15901591
"""
15911592
Mark years that are multiple of base on a given month and day
15921593
(default jan 1).
15931594
"""
1594-
DateLocator.__init__(self, tz)
1595+
super().__init__(tz, **kwargs)
15951596
self.base = ticker._Edge_integer(base, 0)
15961597
self.replaced = {'month': month,
15971598
'day': day,
@@ -1660,7 +1661,8 @@ class MonthLocator(RRuleLocator):
16601661
"""
16611662
Make ticks on occurrences of each month, e.g., 1, 3, 12.
16621663
"""
1663-
def __init__(self, bymonth=None, bymonthday=1, interval=1, tz=None):
1664+
def __init__(self, bymonth=None, bymonthday=1, interval=1, tz=None,
1665+
**kwargs):
16641666
"""
16651667
Mark every month in *bymonth*; *bymonth* can be an int or
16661668
sequence. Default is ``range(1,13)``, i.e. every month.
@@ -1678,15 +1680,15 @@ def __init__(self, bymonth=None, bymonthday=1, interval=1, tz=None):
16781680

16791681
rule = rrulewrapper(MONTHLY, bymonth=bymonth, bymonthday=bymonthday,
16801682
interval=interval, **self.hms0d)
1681-
RRuleLocator.__init__(self, rule, tz)
1683+
super().__init__(rule, tz, **kwargs)
16821684

16831685

16841686
class WeekdayLocator(RRuleLocator):
16851687
"""
16861688
Make ticks on occurrences of each weekday.
16871689
"""
16881690

1689-
def __init__(self, byweekday=1, interval=1, tz=None):
1691+
def __init__(self, byweekday=1, interval=1, tz=None, **kwargs):
16901692
"""
16911693
Mark every weekday in *byweekday*; *byweekday* can be a number or
16921694
sequence.
@@ -1706,15 +1708,15 @@ def __init__(self, byweekday=1, interval=1, tz=None):
17061708

17071709
rule = rrulewrapper(DAILY, byweekday=byweekday,
17081710
interval=interval, **self.hms0d)
1709-
RRuleLocator.__init__(self, rule, tz)
1711+
super().__init__(rule, tz, **kwargs)
17101712

17111713

17121714
class DayLocator(RRuleLocator):
17131715
"""
17141716
Make ticks on occurrences of each day of the month. For example,
17151717
1, 15, 30.
17161718
"""
1717-
def __init__(self, bymonthday=None, interval=1, tz=None):
1719+
def __init__(self, bymonthday=None, interval=1, tz=None, **kwargs):
17181720
"""
17191721
Mark every day in *bymonthday*; *bymonthday* can be an int or
17201722
sequence.
@@ -1733,14 +1735,14 @@ def __init__(self, bymonthday=None, interval=1, tz=None):
17331735

17341736
rule = rrulewrapper(DAILY, bymonthday=bymonthday,
17351737
interval=interval, **self.hms0d)
1736-
RRuleLocator.__init__(self, rule, tz)
1738+
super().__init__(rule, tz, **kwargs)
17371739

17381740

17391741
class HourLocator(RRuleLocator):
17401742
"""
17411743
Make ticks on occurrences of each hour.
17421744
"""
1743-
def __init__(self, byhour=None, interval=1, tz=None):
1745+
def __init__(self, byhour=None, interval=1, tz=None, **kwargs):
17441746
"""
17451747
Mark every hour in *byhour*; *byhour* can be an int or sequence.
17461748
Default is to tick every hour: ``byhour=range(24)``
@@ -1753,14 +1755,14 @@ def __init__(self, byhour=None, interval=1, tz=None):
17531755

17541756
rule = rrulewrapper(HOURLY, byhour=byhour, interval=interval,
17551757
byminute=0, bysecond=0)
1756-
RRuleLocator.__init__(self, rule, tz)
1758+
super().__init__(rule, tz, **kwargs)
17571759

17581760

17591761
class MinuteLocator(RRuleLocator):
17601762
"""
17611763
Make ticks on occurrences of each minute.
17621764
"""
1763-
def __init__(self, byminute=None, interval=1, tz=None):
1765+
def __init__(self, byminute=None, interval=1, tz=None, **kwargs):
17641766
"""
17651767
Mark every minute in *byminute*; *byminute* can be an int or
17661768
sequence. Default is to tick every minute: ``byminute=range(60)``
@@ -1773,14 +1775,14 @@ def __init__(self, byminute=None, interval=1, tz=None):
17731775

17741776
rule = rrulewrapper(MINUTELY, byminute=byminute, interval=interval,
17751777
bysecond=0)
1776-
RRuleLocator.__init__(self, rule, tz)
1778+
super().__init__(rule, tz, **kwargs)
17771779

17781780

17791781
class SecondLocator(RRuleLocator):
17801782
"""
17811783
Make ticks on occurrences of each second.
17821784
"""
1783-
def __init__(self, bysecond=None, interval=1, tz=None):
1785+
def __init__(self, bysecond=None, interval=1, tz=None, **kwargs):
17841786
"""
17851787
Mark every second in *bysecond*; *bysecond* can be an int or
17861788
sequence. Default is to tick every second: ``bysecond = range(60)``
@@ -1793,7 +1795,7 @@ def __init__(self, bysecond=None, interval=1, tz=None):
17931795
bysecond = range(60)
17941796

17951797
rule = rrulewrapper(SECONDLY, bysecond=bysecond, interval=interval)
1796-
RRuleLocator.__init__(self, rule, tz)
1798+
super().__init__(self, rule, tz, **kwargs)
17971799

17981800

17991801
class MicrosecondLocator(DateLocator):
@@ -1815,12 +1817,13 @@ class MicrosecondLocator(DateLocator):
18151817
early years; using year 0001 is recommended.
18161818
18171819
"""
1818-
def __init__(self, interval=1, tz=None):
1820+
def __init__(self, interval=1, tz=None, **kwargs):
18191821
"""
18201822
*interval* is the interval between each iteration. For
18211823
example, if ``interval=2``, mark every second microsecond.
18221824
18231825
"""
1826+
super().__init__(**kwargs)
18241827
self._interval = interval
18251828
self._wrapped_locator = ticker.MultipleLocator(interval)
18261829
self.tz = tz

lib/matplotlib/ticker.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,19 @@ class Locator(TickHelper):
14691469
# many ticks are generated.
14701470
MAXTICKS = 1000
14711471

1472+
def __init__(self, *args, enable_deconflict=True, **kwargs):
1473+
super().__init__(*args, **kwargs)
1474+
self._enable_deconflict = enable_deconflict
1475+
1476+
def get_enable_deconfilct(self):
1477+
return self._enable_deconflict
1478+
1479+
def set_enable_deconflict(self, value):
1480+
self._enable_deconflict = bool(value)
1481+
1482+
enable_deconflict = property(get_enable_deconfilct,
1483+
set_enable_deconflict)
1484+
14721485
def tick_values(self, vmin, vmax):
14731486
"""
14741487
Return the values of the located ticks given **vmin** and **vmax**.
@@ -1564,8 +1577,9 @@ class IndexLocator(Locator):
15641577
index plotting; i.e., the axis is 0, len(data). This is mainly
15651578
useful for x ticks.
15661579
"""
1567-
def __init__(self, base, offset):
1580+
def __init__(self, base, offset, **kwargs):
15681581
'place ticks on the i-th data points where (i-offset)%base==0'
1582+
super().__init__(**kwargs)
15691583
self._base = base
15701584
self.offset = offset
15711585

@@ -1597,7 +1611,8 @@ class FixedLocator(Locator):
15971611
the chosen ticks.
15981612
"""
15991613

1600-
def __init__(self, locs, nbins=None):
1614+
def __init__(self, locs, nbins=None, **kwargs):
1615+
super().__init__(**kwargs)
16011616
self.locs = np.asarray(locs)
16021617
self.nbins = max(nbins, 2) if nbins is not None else None
16031618

@@ -1660,10 +1675,11 @@ class LinearLocator(Locator):
16601675
be nice
16611676
16621677
"""
1663-
def __init__(self, numticks=None, presets=None):
1678+
def __init__(self, numticks=None, presets=None, **kwargs):
16641679
"""
16651680
Use presets to set locs based on lom. A dict mapping vmin, vmax->locs
16661681
"""
1682+
super().__init__(**kwargs)
16671683
self.numticks = numticks
16681684
if presets is None:
16691685
self.presets = {}
@@ -1775,7 +1791,8 @@ class MultipleLocator(Locator):
17751791
Set a tick on each integer multiple of a base within the view interval.
17761792
"""
17771793

1778-
def __init__(self, base=1.0):
1794+
def __init__(self, base=1.0, **kwargs):
1795+
super().__init__(**kwargs)
17791796
self._edge = _Edge_integer(base, 0)
17801797

17811798
def set_params(self, base):
@@ -1919,6 +1936,8 @@ def __init__(self, *args, **kwargs):
19191936
this minimum number of ticks.
19201937
19211938
"""
1939+
enable_deconflict = kwargs.pop('enable_deconflict', True)
1940+
super().__init__(enable_deconflict=enable_deconflict)
19221941
if args:
19231942
if 'nbins' in kwargs:
19241943
cbook.deprecated("3.1",
@@ -2202,7 +2221,8 @@ class LogLocator(Locator):
22022221
Determine the tick locations for log axes
22032222
"""
22042223

2205-
def __init__(self, base=10.0, subs=(1.0,), numdecs=4, numticks=None):
2224+
def __init__(self, base=10.0, subs=(1.0,), numdecs=4, numticks=None,
2225+
**kwargs):
22062226
"""
22072227
Place ticks on the locations : subs[j] * base**i
22082228
@@ -2221,6 +2241,7 @@ def __init__(self, base=10.0, subs=(1.0,), numdecs=4, numticks=None):
22212241
equivalent to ``'auto'``.
22222242
22232243
"""
2244+
super().__init__(**kwargs)
22242245
if numticks is None:
22252246
if rcParams['_internal.classic_mode']:
22262247
numticks = 15
@@ -2403,10 +2424,12 @@ class SymmetricalLogLocator(Locator):
24032424
Determine the tick locations for symmetric log axes
24042425
"""
24052426

2406-
def __init__(self, transform=None, subs=None, linthresh=None, base=None):
2427+
def __init__(self, transform=None, subs=None, linthresh=None,
2428+
base=None, **kwargs):
24072429
"""
24082430
place ticks on the location= base**i*subs[j]
24092431
"""
2432+
super().__init__(**kwargs)
24102433
if transform is not None:
24112434
self._base = transform.base
24122435
self._linthresh = transform.linthresh
@@ -2563,10 +2586,11 @@ class LogitLocator(Locator):
25632586
Determine the tick locations for logit axes
25642587
"""
25652588

2566-
def __init__(self, minor=False):
2589+
def __init__(self, minor=False, **kwargs):
25672590
"""
25682591
place ticks on the logit locations
25692592
"""
2593+
super().__init__(**kwargs)
25702594
self.minor = minor
25712595

25722596
def set_params(self, minor=None):
@@ -2656,11 +2680,12 @@ class AutoLocator(MaxNLocator):
26562680
of `~matplotlib.ticker.MaxNLocator`, with parameters *nbins = 'auto'*
26572681
and *steps = [1, 2, 2.5, 5, 10]*.
26582682
"""
2659-
def __init__(self):
2683+
def __init__(self, **kwargs):
26602684
"""
26612685
To know the values of the non-public parameters, please have a
26622686
look to the defaults of `~matplotlib.ticker.MaxNLocator`.
26632687
"""
2688+
super().__init__(**kwargs)
26642689
if rcParams['_internal.classic_mode']:
26652690
nbins = 9
26662691
steps = [1, 2, 5, 10]
@@ -2675,14 +2700,15 @@ class AutoMinorLocator(Locator):
26752700
Dynamically find minor tick positions based on the positions of
26762701
major ticks. The scale must be linear with major ticks evenly spaced.
26772702
"""
2678-
def __init__(self, n=None):
2703+
def __init__(self, n=None, **kwargs):
26792704
"""
26802705
*n* is the number of subdivisions of the interval between
26812706
major ticks; e.g., n=2 will place a single minor tick midway
26822707
between major ticks.
26832708
26842709
If *n* is omitted or None, it will be set to 5 or 4.
26852710
"""
2711+
super().__init__(**kwargs)
26862712
self.ndivs = n
26872713

26882714
def __call__(self):
@@ -2737,7 +2763,8 @@ class OldAutoLocator(Locator):
27372763
view limits and the tick locs.
27382764
27392765
"""
2740-
def __init__(self):
2766+
def __init__(self, **kwargs):
2767+
super().__init__(**kwargs)
27412768
self._locator = LinearLocator()
27422769

27432770
def __call__(self):

0 commit comments

Comments
 (0)