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 551f11b

Browse filesBrowse files
committed
Merge branch 'locator_interface' of git://github.com/pelson/matplotlib into pelson-locator_interface
Conflicts: lib/matplotlib/__init__.py
2 parents 360887a + 4526865 commit 551f11b
Copy full SHA for 551f11b

File tree

Expand file treeCollapse file tree

5 files changed

+171
-41
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+171
-41
lines changed

‎doc/users/whats_new.rst

Copy file name to clipboardExpand all lines: doc/users/whats_new.rst
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ This page just covers the highlights -- for the full story, see the
1717
new in matplotlib-1.2
1818
=====================
1919

20+
Locator interface
21+
-----------------
22+
23+
Philip Elson exposed the intelligence behind the tick Locator classes with a
24+
simple interface. For instance, to get no more than 5 sensible steps which
25+
span the values 10 and 19.5::
26+
27+
>>> import matplotlib.ticker as mticker
28+
>>> locator = mticker.MaxNLocator(nbins=5)
29+
>>> print(locator.tick_values(10, 19.5))
30+
[ 10. 12. 14. 16. 18. 20.]
31+
2032
Tri-Surface Plots
2133
-----------------
2234

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+12-10Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,27 +1003,29 @@ def tk_window_focus():
10031003

10041004
default_test_modules = [
10051005
'matplotlib.tests.test_agg',
1006+
'matplotlib.tests.test_axes',
10061007
'matplotlib.tests.test_backend_svg',
10071008
'matplotlib.tests.test_basic',
10081009
'matplotlib.tests.test_cbook',
1009-
'matplotlib.tests.test_mlab',
1010-
'matplotlib.tests.test_transforms',
1011-
'matplotlib.tests.test_axes',
1012-
'matplotlib.tests.test_figure',
1010+
'matplotlib.tests.test_colorbar',
10131011
'matplotlib.tests.test_dates',
1014-
'matplotlib.tests.test_spines',
1012+
'matplotlib.tests.test_delaunay',
1013+
'matplotlib.tests.test_figure',
10151014
'matplotlib.tests.test_image',
1016-
'matplotlib.tests.test_simplification',
1015+
'matplotlib.tests.test_legend',
10171016
'matplotlib.tests.test_mathtext',
1017+
'matplotlib.tests.test_mlab',
1018+
'matplotlib.tests.test_patches',
1019+
'matplotlib.tests.test_simplification',
1020+
'matplotlib.tests.test_spines',
10181021
'matplotlib.tests.test_text',
1022+
'matplotlib.tests.test_ticker',
10191023
'matplotlib.tests.test_tightlayout',
1020-
'matplotlib.tests.test_delaunay',
1021-
'matplotlib.tests.test_legend',
1022-
'matplotlib.tests.test_colorbar',
1023-
'matplotlib.tests.test_patches',
10241024
'matplotlib.tests.test_triangulation'
1025+
'matplotlib.tests.test_transforms',
10251026
]
10261027

1028+
10271029
def test(verbosity=1):
10281030
"""run the matplotlib test suite"""
10291031
old_backend = rcParams['backend']

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,9 @@ def _autolev(self, z, N):
999999
self.locator = ticker.LogLocator()
10001000
else:
10011001
self.locator = ticker.MaxNLocator(N+1)
1002-
self.locator.create_dummy_axis()
10031002
zmax = self.zmax
10041003
zmin = self.zmin
1005-
self.locator.set_bounds(zmin, zmax)
1006-
lev = self.locator()
1004+
lev = self.locator.tick_values(zmin, zmax)
10071005
self._auto = True
10081006
if self.filled:
10091007
return lev

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboard
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from __future__ import print_function
2+
from nose.tools import assert_equal, assert_raises
3+
from numpy.testing import assert_almost_equal
4+
import numpy as np
5+
6+
import matplotlib.ticker as mticker
7+
8+
9+
def test_MaxNLocator():
10+
loc = mticker.MaxNLocator(nbins=5)
11+
test_value = np.array([ 20., 40., 60., 80., 100.])
12+
assert_almost_equal(loc.tick_values(20, 100), test_value)
13+
14+
test_value = np.array([ 0., 0.0002, 0.0004, 0.0006, 0.0008, 0.001])
15+
assert_almost_equal(loc.tick_values(0.001, 0.0001), test_value)
16+
17+
test_value = np.array([-1.0e+15, -5.0e+14, 0e+00, 5e+14, 1.0e+15])
18+
assert_almost_equal(loc.tick_values(-1e15, 1e15), test_value)
19+
20+
21+
def test_LinearLocator():
22+
loc = mticker.LinearLocator(numticks=3)
23+
test_value = np.array([-0.8, -0.3, 0.2])
24+
assert_almost_equal(loc.tick_values(-0.8, 0.2), test_value)
25+
26+
27+
def test_MultipleLocator():
28+
loc = mticker.MultipleLocator(base=3.147)
29+
test_value = np.array([-6.294, -3.147, 0., 3.147, 6.294, 9.441])
30+
assert_almost_equal(loc.tick_values(-7, 10), test_value)
31+
32+
33+
def test_LogLocator():
34+
loc = mticker.LogLocator(numticks=5)
35+
36+
# make sure the 0 case is covered with an exception
37+
with assert_raises(ValueError):
38+
loc.tick_values(0, 1000)
39+
40+
test_value = np.array([1.00000000e-03, 1.00000000e-01, 1.00000000e+01,
41+
1.00000000e+03, 1.00000000e+05, 1.00000000e+07])
42+
assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value)
43+
44+
loc = mticker.LogLocator(base=2)
45+
test_value = np.array([1., 2., 4., 8., 16., 32., 64., 128.])
46+
assert_almost_equal(loc.tick_values(1, 100), test_value)
47+
48+
49+
if __name__=='__main__':
50+
import nose
51+
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

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