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

Skip to content

Commit 7a354ae

Browse files
committed
Merge branch 'v2.x'
2 parents eadafc6 + fe721a6 commit 7a354ae

10 files changed

Lines changed: 97 additions & 37 deletions

File tree

doc/api/api_changes.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ CocoaAgg backend removed
4040
~~~~~~~~~~~~~~~~~~~~~~~~
4141
The deprecated and not fully functional CocoaAgg backend has been removed.
4242

43+
`round` removed from TkAgg Backend
44+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45+
The TkAgg backend had its own implementation of the `round` function. This
46+
was unused internally and has been removed. Instead, use either the
47+
`round` builtin function or `numpy.round`.
48+
4349
'hold' functionality deprecated
4450
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4551
The 'hold' keyword argument and all functions and methods related
@@ -135,6 +141,16 @@ the kwarg is None which internally sets it to the 'auto' string,
135141
triggering a new algorithm for adjusting the maximum according
136142
to the axis length relative to the ticklabel font size.
137143

144+
`matplotlib.ticker.LogFormatter` gains minor_thresholds kwarg
145+
-------------------------------------------------------------
146+
147+
Previously, minor ticks on log-scaled axes were not labeled by
148+
default. An algorithm has been added to the
149+
`~matplotlib.ticker.LogFormatter` to control the labeling of
150+
ticks between integer powers of the base. The algorithm uses
151+
two parameters supplied in a kwarg tuple named 'minor_thresholds'.
152+
See the docstring for further explanation.
153+
138154

139155
New defaults for 3D quiver function in mpl_toolkits.mplot3d.axes3d.py
140156
---------------------------------------------------------------------

doc/users/dflt_style_changes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,11 @@ or create a new `~matplotlib.ticker.MaxNLocator`::
976976
import matplotlib.ticker as mticker
977977
ax.set_major_locator(mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10])
978978

979+
The algorithm used by `~matplotlib.ticker.MaxNLocator` has been
980+
improved, and this may change the choice of tick locations in some
981+
cases. This also affects `~matplotlib.ticker.AutoLocator`, which
982+
uses ``MaxNLocator`` internally.
983+
979984
For a log-scaled axis the default locator is the
980985
`~matplotlib.ticker.LogLocator`. Previously the maximum number
981986
of ticks was set to 15, and could not be changed. Now there is a
@@ -1050,6 +1055,15 @@ Z-order
10501055
``rcParams['axes.axisbelow'] = False``.
10511056

10521057

1058+
``LogFormatter`` labeling of minor ticks
1059+
========================================
1060+
1061+
Minor ticks on a log axis are now labeled when the axis view limits
1062+
span a range less than or equal to the interval between two major
1063+
ticks. See `~matplotlib.ticker.LogFormatter` for details. The
1064+
minor tick labeling is turned off when using ``mpl.style.use('classic')``,
1065+
but cannot be controlled independently via ``rcParams``.
1066+
10531067

10541068
``ScalarFormatter`` tick label formatting with offsets
10551069
======================================================

examples/pylab_examples/date_index_formatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from __future__ import print_function
12-
import numpy
12+
import numpy as np
1313
from matplotlib.mlab import csv2rec
1414
import matplotlib.pyplot as plt
1515
import matplotlib.cbook as cbook
@@ -27,7 +27,7 @@ def __init__(self, dates, fmt='%Y-%m-%d'):
2727

2828
def __call__(self, x, pos=0):
2929
'Return the label for time x at position pos'
30-
ind = int(round(x))
30+
ind = int(np.round(x))
3131
if ind >= len(self.dates) or ind < 0:
3232
return ''
3333

@@ -37,6 +37,6 @@ def __call__(self, x, pos=0):
3737

3838
fig, ax = plt.subplots()
3939
ax.xaxis.set_major_formatter(formatter)
40-
ax.plot(numpy.arange(len(r)), r.close, 'o-')
40+
ax.plot(np.arange(len(r)), r.close, 'o-')
4141
fig.autofmt_xdate()
4242
plt.show()

examples/user_interfaces/embedding_in_wx4.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def __init__(self, canvas, cankill):
3737
# probably want to add your own.
3838
if 'phoenix' in wx.PlatformInfo:
3939
self.AddTool(self.ON_CUSTOM, 'Click me',
40-
_load_bitmap('stock_left.xpm'),
40+
_load_bitmap('back.png'),
4141
'Activate custom contol')
4242
self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
4343
else:
44-
self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
44+
self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('back.png'),
4545
'Click me', 'Activate custom contol')
4646
self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
4747

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
210210

211211
#print x, y, int(x), int(y), s
212212
self._renderer.draw_text_image(
213-
font, round(x - xd + xo), round(y + yd + yo) + 1, angle, gc)
213+
font, np.round(x - xd + xo), np.round(y + yd + yo) + 1, angle, gc)
214214

215215
def get_text_width_height_descent(self, s, prop, ismath):
216216
"""
@@ -257,8 +257,8 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
257257
w, h, d = self.get_text_width_height_descent(s, prop, ismath)
258258
xd = d * sin(radians(angle))
259259
yd = d * cos(radians(angle))
260-
x = round(x + xd)
261-
y = round(y + yd)
260+
x = np.round(x + xd)
261+
y = np.round(y + yd)
262262

263263
self._renderer.draw_text_image(Z, x, y, angle, gc)
264264

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
}
5151

5252

53-
def round(x):
54-
return int(math.floor(x+0.5))
55-
5653
def raise_msg_to_str(msg):
5754
"""msg is a return arg from a raise. Join with new lines"""
5855
if not is_string_like(msg):

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def flush_images():
152152
gc = renderer.new_gc()
153153
gc.set_clip_rectangle(parent.bbox)
154154
gc.set_clip_path(parent.get_clip_path())
155-
renderer.draw_image(gc, round(l), round(b), data)
155+
renderer.draw_image(gc, np.round(l), np.round(b), data)
156156
gc.restore()
157157
del image_group[:]
158158

lib/matplotlib/scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def set_default_locators_and_formatters(self, axis):
251251
axis.set_minor_locator(LogLocator(self.base, self.subs))
252252
axis.set_minor_formatter(
253253
LogFormatterSciNotation(self.base,
254-
labelOnlyBase=self.subs))
254+
labelOnlyBase=bool(self.subs)))
255255

256256
def get_transform(self):
257257
"""

lib/matplotlib/tests/test_ticker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_MaxNLocator_integer():
3232
test_value = np.array([-1, 0, 1, 2])
3333
assert_almost_equal(loc.tick_values(-0.1, 1.1), test_value)
3434

35-
test_value = np.array([-0.25, 0, 0.25, 0.5, 0.75, 1])
35+
test_value = np.array([-0.3, 0, 0.3, 0.6, 0.9, 1.2])
3636
assert_almost_equal(loc.tick_values(-0.1, 0.95), test_value)
3737

3838

@@ -236,7 +236,7 @@ def _sub_labels(axis, subs=()):
236236
assert label_test == label_expected
237237

238238

239-
@cleanup
239+
@cleanup(style='default')
240240
def test_LogFormatter_sublabel():
241241
# test label locator
242242
fig, ax = plt.subplots()

lib/matplotlib/ticker.py

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,12 @@ class LogFormatter(Formatter):
866866
major and minor ticks; the tick locations might be set manually,
867867
or by a locator that puts ticks at integer powers of base and
868868
at intermediate locations. For this situation, disable the
869-
minor_thresholds logic by using ``minor_thresholds=(np.inf, np.inf)``.
869+
minor_thresholds logic by using ``minor_thresholds=(np.inf, np.inf)``,
870+
so that all ticks will be labeled.
871+
872+
To disable labeling of minor ticks when 'labelOnlyBase' is False,
873+
use ``minor_thresholds=(0, 0)``. This is the default for the
874+
"classic" style.
870875
871876
Examples
872877
--------
@@ -877,14 +882,18 @@ class LogFormatter(Formatter):
877882
To label all minor ticks when the view limits span up to 1.5
878883
decades, use ``minor_thresholds=(1.5, 1.5)``.
879884
880-
881885
"""
882886
def __init__(self, base=10.0, labelOnlyBase=False,
883-
minor_thresholds=(1, 0.4),
887+
minor_thresholds=None,
884888
linthresh=None):
885889

886890
self._base = float(base)
887891
self.labelOnlyBase = labelOnlyBase
892+
if minor_thresholds is None:
893+
if rcParams['_internal.classic_mode']:
894+
minor_thresholds = (0, 0)
895+
else:
896+
minor_thresholds = (1, 0.4)
888897
self.minor_thresholds = minor_thresholds
889898
self._sublabels = None
890899
self._linthresh = linthresh
@@ -925,7 +934,6 @@ def set_locs(self, locs=None):
925934
b = self._base
926935

927936
vmin, vmax = self.axis.get_view_interval()
928-
self.d = abs(vmax - vmin)
929937

930938
# Handle symlog case:
931939
linthresh = self._linthresh
@@ -957,15 +965,20 @@ def set_locs(self, locs=None):
957965
# Add labels between bases at log-spaced coefficients;
958966
# include base powers in case the locations include
959967
# "major" and "minor" points, as in colorbar.
960-
c = np.logspace(0, 1, b//2 + 1, base=b)
968+
c = np.logspace(0, 1, int(b)//2 + 1, base=b)
961969
self._sublabels = set(np.round(c))
970+
# For base 10, this yields (1, 2, 3, 4, 6, 10).
962971
else:
963-
self._sublabels = set(np.linspace(1, b, b))
972+
# Label all integer multiples of base**n.
973+
self._sublabels = set(np.arange(1, b + 1))
964974

965975
def __call__(self, x, pos=None):
966976
"""
967977
Return the format for tick val `x`.
968978
"""
979+
vmin, vmax = self.axis.get_view_interval()
980+
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
981+
d = abs(vmax - vmin)
969982
b = self._base
970983
if x == 0.0:
971984
return '0'
@@ -986,7 +999,7 @@ def __call__(self, x, pos=None):
986999
elif x < 1:
9871000
s = '%1.0e' % x
9881001
else:
989-
s = self.pprint_val(x, self.d)
1002+
s = self.pprint_val(x, d)
9901003
if sign == -1:
9911004
s = '-%s' % s
9921005

@@ -1795,6 +1808,33 @@ def __init__(self, *args, **kwargs):
17951808
self.set_params(**self.default_params)
17961809
self.set_params(**kwargs)
17971810

1811+
@staticmethod
1812+
def _validate_steps(steps):
1813+
if not np.iterable(steps):
1814+
raise ValueError('steps argument must be a sequence of numbers '
1815+
'from 1 to 10')
1816+
steps = np.asarray(steps)
1817+
if np.any(np.diff(steps) <= 0):
1818+
raise ValueError('steps argument must be uniformly increasing')
1819+
if steps[-1] > 10 or steps[0] < 1:
1820+
warnings.warn('Steps argument should be a sequence of numbers\n'
1821+
'increasing from 1 to 10, inclusive. Behavior with\n'
1822+
'values outside this range is undefined, and will\n'
1823+
'raise a ValueError in future versions of mpl.')
1824+
if steps[0] != 1:
1825+
steps = np.hstack((1, steps))
1826+
if steps[-1] != 10:
1827+
steps = np.hstack((steps, 10))
1828+
return steps
1829+
1830+
@staticmethod
1831+
def _staircase(steps):
1832+
# Make an extended staircase within which the needed
1833+
# step will be found. This is probably much larger
1834+
# than necessary.
1835+
flights = (0.1 * steps[:-1], steps, 10 * steps[1])
1836+
return np.hstack(flights)
1837+
17981838
def set_params(self, **kwargs):
17991839
"""Set parameters within this locator."""
18001840
if 'nbins' in kwargs:
@@ -1816,23 +1856,16 @@ def set_params(self, **kwargs):
18161856
if 'steps' in kwargs:
18171857
steps = kwargs['steps']
18181858
if steps is None:
1819-
self._steps = [1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10]
1859+
self._steps = np.array([1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10])
18201860
else:
1821-
if int(steps[-1]) != 10:
1822-
steps = list(steps)
1823-
steps.append(10)
1824-
self._steps = steps
1825-
# Make an extended staircase within which the needed
1826-
# step will be found. This is probably much larger
1827-
# than necessary.
1828-
flights = (0.1 * np.array(self._steps[:-1]),
1829-
self._steps,
1830-
[10 * self._steps[1]])
1831-
self._extended_steps = np.hstack(flights)
1861+
self._steps = self._validate_steps(steps)
1862+
self._extended_steps = self._staircase(self._steps)
18321863
if 'integer' in kwargs:
18331864
self._integer = kwargs['integer']
18341865
if self._integer:
1835-
self._steps = [n for n in self._steps if _divmod(n, 1)[1] < 0.001]
1866+
self._steps = np.array([n for n in self._steps
1867+
if _divmod(n, 1)[1] < 0.001])
1868+
self._extended_steps = self._staircase(self._steps)
18361869
if 'min_n_ticks' in kwargs:
18371870
self._min_n_ticks = max(1, kwargs['min_n_ticks'])
18381871

@@ -1870,8 +1903,8 @@ def _raw_ticks(self, vmin, vmax):
18701903
step = max(1, step)
18711904
best_vmin = (_vmin // step) * step
18721905

1873-
low = round(Base(step).le(_vmin - best_vmin) / step)
1874-
high = round(Base(step).ge(_vmax - best_vmin) / step)
1906+
low = np.round(Base(step).le(_vmin - best_vmin) / step)
1907+
high = np.round(Base(step).ge(_vmax - best_vmin) / step)
18751908
ticks = np.arange(low, high + 1) * step + best_vmin + offset
18761909
nticks = ((ticks <= vmax) & (ticks >= vmin)).sum()
18771910
if nticks >= self._min_n_ticks:

0 commit comments

Comments
 (0)