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 5fd10ae

Browse filesBrowse files
committed
Merge remote-tracking branch 'matplotlib/v2.x' into realmaster
2 parents c259a55 + 7cea22c commit 5fd10ae
Copy full SHA for 5fd10ae

File tree

Expand file treeCollapse file tree

6 files changed

+33
-25
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+33
-25
lines changed

‎examples/axes_grid1/inset_locator_demo.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/inset_locator_demo.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def add_sizebar(ax, size):
3232
ax2.set_aspect(1.)
3333

3434
axins = zoomed_inset_axes(ax2, 0.5, loc=1) # zoom = 0.5
35+
# fix the number of ticks on the inset axes
36+
axins.yaxis.get_major_locator().set_params(nbins=7)
37+
axins.xaxis.get_major_locator().set_params(nbins=7)
3538

3639
plt.xticks(visible=False)
3740
plt.yticks(visible=False)

‎examples/axes_grid1/inset_locator_demo2.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/inset_locator_demo2.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def get_demo_image():
3434
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
3535
axins.set_xlim(x1, x2)
3636
axins.set_ylim(y1, y2)
37+
# fix the number of ticks on the inset axes
38+
axins.yaxis.get_major_locator().set_params(nbins=7)
39+
axins.xaxis.get_major_locator().set_params(nbins=7)
3740

3841
plt.xticks(visible=False)
3942
plt.yticks(visible=False)

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+15-21Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ def __init__(self, axes, pickradius=15):
664664
# Initialize here for testing; later add API
665665
self._major_tick_kw = dict()
666666
self._minor_tick_kw = dict()
667-
self._tick_space = None
668667

669668
self.cla()
670669
self._set_scale('linear')
@@ -796,7 +795,6 @@ def set_tick_params(self, which='major', reset=False, **kw):
796795
for tick in self.minorTicks:
797796
tick._apply_params(**self._minor_tick_kw)
798797
self.stale = True
799-
self._tick_space = None
800798

801799
@staticmethod
802800
def _translate_tick_kw(kw, to_init_kw=True):
@@ -2018,16 +2016,14 @@ def set_default_intervals(self):
20182016
self.stale = True
20192017

20202018
def get_tick_space(self):
2021-
if self._tick_space is None:
2022-
ends = self.axes.transAxes.transform([[0, 0], [1, 0]])
2023-
length = ((ends[1][0] - ends[0][0]) / self.axes.figure.dpi) * 72.0
2024-
tick = self._get_tick(True)
2025-
# There is a heuristic here that the aspect ratio of tick text
2026-
# is no more than 3:1
2027-
size = tick.label1.get_size() * 3
2028-
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2029-
self._tick_space = np.floor(length / size)
2030-
return self._tick_space
2019+
ends = self.axes.transAxes.transform([[0, 0], [1, 0]])
2020+
length = ((ends[1][0] - ends[0][0]) / self.axes.figure.dpi) * 72.0
2021+
tick = self._get_tick(True)
2022+
# There is a heuristic here that the aspect ratio of tick text
2023+
# is no more than 3:1
2024+
size = tick.label1.get_size() * 3
2025+
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2026+
return np.floor(length / size)
20312027

20322028

20332029
class YAxis(Axis):
@@ -2361,12 +2357,10 @@ def set_default_intervals(self):
23612357
self.stale = True
23622358

23632359
def get_tick_space(self):
2364-
if self._tick_space is None:
2365-
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
2366-
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
2367-
tick = self._get_tick(True)
2368-
# Having a spacing of at least 2 just looks good.
2369-
size = tick.label1.get_size() * 2.0
2370-
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2371-
self._tick_space = np.floor(length / size)
2372-
return self._tick_space
2360+
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
2361+
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
2362+
tick = self._get_tick(True)
2363+
# Having a spacing of at least 2 just looks good.
2364+
size = tick.label1.get_size() * 2.0
2365+
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2366+
return np.floor(length / size)

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,9 +4282,16 @@ def _helper_y(ax):
42824282

42834283

42844284
@cleanup
4285-
def test_broken_barh_empty():
4285+
def test_adjust_numtick_aspect():
42864286
fig, ax = plt.subplots()
4287-
ax.broken_barh([], (.1, .5))
4287+
ax.yaxis.get_major_locator().set_params(nbins='auto')
4288+
ax.set_xlim(0, 1000)
4289+
ax.set_aspect('equal')
4290+
fig.canvas.draw()
4291+
assert len(ax.yaxis.get_major_locator()()) == 2
4292+
ax.set_ylim(0, 1000)
4293+
fig.canvas.draw()
4294+
assert len(ax.yaxis.get_major_locator()()) > 2
42884295

42894296

42904297
@cleanup

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ def set_params(self, **kwargs):
14341434
def bin_boundaries(self, vmin, vmax):
14351435
nbins = self._nbins
14361436
if nbins == 'auto':
1437-
nbins = min(self.axis.get_tick_space(), 9)
1437+
nbins = max(min(self.axis.get_tick_space(), 9), 1)
14381438
scale, offset = scale_range(vmin, vmax, nbins)
14391439
if self._integer:
14401440
scale = max(1, scale)

‎lib/mpl_toolkits/tests/test_axes_grid1.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_axes_grid1.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def get_demo_image():
134134
axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
135135
axins.imshow(Z2, extent=extent, interpolation="nearest",
136136
origin="lower")
137-
137+
axins.yaxis.get_major_locator().set_params(nbins=7)
138+
axins.xaxis.get_major_locator().set_params(nbins=7)
138139
# sub region of the original image
139140
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
140141
axins.set_xlim(x1, x2)

0 commit comments

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