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

Skip to content

Commit 729d219

Browse files
dstansbyNelleV
authored andcommitted
Merge pull request #7959 from scopatz/size0tick
Allow zero sized ticks
1 parent 9b6f7c1 commit 729d219

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,10 @@ def get_tick_space(self):
20212021
# There is a heuristic here that the aspect ratio of tick text
20222022
# is no more than 3:1
20232023
size = tick.label1.get_size() * 3
2024-
return int(np.floor(length / size))
2024+
if size > 0:
2025+
return int(np.floor(length / size))
2026+
else:
2027+
return 2**31 - 1
20252028

20262029

20272030
class YAxis(Axis):
@@ -2354,4 +2357,7 @@ def get_tick_space(self):
23542357
tick = self._get_tick(True)
23552358
# Having a spacing of at least 2 just looks good.
23562359
size = tick.label1.get_size() * 2.0
2357-
return int(np.floor(length / size))
2360+
if size > 0:
2361+
return int(np.floor(length / size))
2362+
else:
2363+
return 2**31 - 1

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,16 @@ def test_manage_xticks():
23012301
assert_array_equal(old_xlim, new_xlim)
23022302

23032303

2304+
@cleanup
2305+
def test_tick_space_size_0():
2306+
# allow font size to be zero, which affects ticks when there is
2307+
# no other text in the figure.
2308+
plt.plot([0, 1], [0, 1])
2309+
matplotlib.rcParams.update({'font.size': 0})
2310+
b = io.BytesIO()
2311+
plt.savefig(b, dpi=80, format='raw')
2312+
2313+
23042314
@image_comparison(baseline_images=['errorbar_basic', 'errorbar_mixed',
23052315
'errorbar_basic'])
23062316
def test_errorbar():

0 commit comments

Comments
 (0)