Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5a2f962

Browse filesBrowse files
committed
Simplify -- use nbins == None to indicate auto
1 parent 2e1af1f commit 5a2f962
Copy full SHA for 5a2f962

File tree

Expand file treeCollapse file tree

4 files changed

+17
-75
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+17
-75
lines changed

‎examples/units/basic_units.py

Copy file name to clipboardExpand all lines: examples/units/basic_units.py
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import matplotlib.ticker as ticker
77
from matplotlib.axes import Axes
88
from matplotlib.cbook import iterable
9-
from matplotlib import rcParams
109

1110

1211
class ProxyDelegate(object):
@@ -329,12 +328,8 @@ def axisinfo(unit, axis):
329328
label=unit.fullname,
330329
)
331330
elif unit == degrees:
332-
if rcParams['_internal.classic_mode']:
333-
locator = ticker.ClassicAutoLocator()
334-
else:
335-
locator = ticker.AutoLocator()
336331
return units.AxisInfo(
337-
majloc=locator,
332+
majloc=ticker.AutoLocator(),
338333
majfmt=ticker.FormatStrFormatter(r'$%i^\circ$'),
339334
label=unit.fullname,
340335
)

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,7 @@ def get_children(self):
711711

712712
def cla(self):
713713
'clear the current axis'
714-
if rcParams['_internal.classic_mode']:
715-
self.set_major_locator(mticker.ClassicAutoLocator())
716-
else:
717-
self.set_major_locator(mticker.AutoLocator())
714+
self.set_major_locator(mticker.AutoLocator())
718715
self.set_major_formatter(mticker.ScalarFormatter())
719716
self.set_minor_locator(mticker.NullLocator())
720717
self.set_minor_formatter(mticker.NullFormatter())
@@ -2006,7 +2003,7 @@ def get_tick_space(self):
20062003
length = ((ends[1][0] - ends[0][0]) / self.axes.figure.dpi) * 72.0
20072004
tick = self._get_tick(True)
20082005
# There is a heuristic here that the aspect ratio of tick text
2009-
# is no more than 2:1
2006+
# is no more than 3:1
20102007
size = tick.label1.get_size() * 3
20112008
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
20122009
self._tick_space = np.floor(length / size)

‎lib/matplotlib/scale.py

Copy file name to clipboardExpand all lines: lib/matplotlib/scale.py
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import numpy as np
77
from numpy import ma
88

9-
from matplotlib import rcParams
109
from matplotlib.cbook import dedent
1110
from matplotlib.ticker import (NullFormatter, ScalarFormatter,
1211
LogFormatterMathtext, LogitFormatter)
1312
from matplotlib.ticker import (NullLocator, LogLocator, AutoLocator,
14-
SymmetricalLogLocator, LogitLocator,
15-
ClassicAutoLocator)
13+
SymmetricalLogLocator, LogitLocator)
1614
from matplotlib.transforms import Transform, IdentityTransform
1715
from matplotlib import docstring
1816

@@ -73,11 +71,7 @@ def set_default_locators_and_formatters(self, axis):
7371
Set the locators and formatters to reasonable defaults for
7472
linear scaling.
7573
"""
76-
if rcParams['_internal.classic_mode']:
77-
locator = ClassicAutoLocator()
78-
else:
79-
locator = AutoLocator()
80-
axis.set_major_locator(locator)
74+
axis.set_major_locator(AutoLocator())
8175
axis.set_major_formatter(ScalarFormatter())
8276
axis.set_minor_locator(NullLocator())
8377
axis.set_minor_formatter(NullFormatter())

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+12-56Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ class MaxNLocator(Locator):
13371337
"""
13381338
Select no more than N intervals at nice locations.
13391339
"""
1340-
default_params = dict(nbins=10,
1340+
default_params = dict(nbins=None,
13411341
steps=None,
13421342
trim=True,
13431343
integer=False,
@@ -1349,7 +1349,9 @@ def __init__(self, *args, **kwargs):
13491349
Keyword args:
13501350
13511351
*nbins*
1352-
Maximum number of intervals; one less than max number of ticks.
1352+
Maximum number of intervals; one less than max number of
1353+
ticks. If `None`, the number of bins will be
1354+
automatically determined based on the length of the axis.
13531355
13541356
*steps*
13551357
Sequence of nice numbers starting with 1 and ending with 10;
@@ -1416,6 +1418,8 @@ def set_params(self, **kwargs):
14161418

14171419
def bin_boundaries(self, vmin, vmax):
14181420
nbins = self._nbins
1421+
if nbins is None:
1422+
nbins = self.axis.get_tick_space()
14191423
scale, offset = scale_range(vmin, vmax, nbins)
14201424
if self._integer:
14211425
scale = max(1, scale)
@@ -1472,52 +1476,6 @@ def view_limits(self, dmin, dmax):
14721476
return dmin, dmax
14731477

14741478

1475-
class AutoSpacedLocator(MaxNLocator):
1476-
"""
1477-
Behaves like a MaxNLocator, except N is automatically determined
1478-
from the length of the axis.
1479-
"""
1480-
def __init__(self, steps=None, integer=False, symmetric=False, prune=None):
1481-
"""
1482-
Keyword args:
1483-
1484-
*steps*
1485-
Sequence of nice numbers starting with 1 and ending with 10;
1486-
e.g., [1, 2, 4, 5, 10]
1487-
1488-
*integer*
1489-
If True, ticks will take only integer values.
1490-
1491-
*symmetric*
1492-
If True, autoscaling will result in a range symmetric
1493-
about zero.
1494-
1495-
*prune*
1496-
['lower' | 'upper' | 'both' | None]
1497-
Remove edge ticks -- useful for stacked or ganged plots
1498-
where the upper tick of one axes overlaps with the lower
1499-
tick of the axes above it.
1500-
If prune=='lower', the smallest tick will
1501-
be removed. If prune=='upper', the largest tick will be
1502-
removed. If prune=='both', the largest and smallest ticks
1503-
will be removed. If prune==None, no ticks will be removed.
1504-
1505-
"""
1506-
self.set_params(**self.default_params)
1507-
self.set_params(steps=steps, integer=integer, symmetric=symmetric,
1508-
prune=prune)
1509-
1510-
def set_params(self, **kwargs):
1511-
if 'nbins' in kwargs:
1512-
raise TypeError(
1513-
"set_params got an unexpected keyword argument 'nbins'")
1514-
return super(AutoSpacedLocator, self).set_params(**kwargs)
1515-
1516-
def __call__(self):
1517-
self._nbins = self.axis.get_tick_space()
1518-
return super(AutoSpacedLocator, self).__call__()
1519-
1520-
15211479
def decade_down(x, base=10):
15221480
'floor x to the nearest lower decade'
15231481
if x == 0.0:
@@ -1945,15 +1903,13 @@ def tick_values(self, vmin, vmax):
19451903
return self.raise_if_exceeds(np.array(ticklocs))
19461904

19471905

1948-
class AutoLocator(AutoSpacedLocator):
1906+
class AutoLocator(MaxNLocator):
19491907
def __init__(self):
1950-
AutoSpacedLocator.__init__(self, steps=[1, 2, 5, 10])
1951-
1952-
1953-
class ClassicAutoLocator(MaxNLocator):
1954-
# Used only for classic style
1955-
def __init__(self):
1956-
MaxNLocator.__init__(self, nbins=9, steps=[1, 2, 5, 10])
1908+
if rcParams['_internal.classic_mode']:
1909+
nbins = 9
1910+
else:
1911+
nbins = None
1912+
MaxNLocator.__init__(self, nbins=nbins, steps=[1, 2, 5, 10])
19571913

19581914

19591915
class AutoMinorLocator(Locator):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.