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

Skip to content

Commit 0799250

Browse files
authored
Merge pull request #7959 from scopatz/size0tick
Allow zero sized ticks
2 parents 8b630a4 + 7df6ef2 commit 0799250

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/matplotlib/axis.py

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

20252028

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

lib/matplotlib/tests/test_axes.py

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

23782378

2379+
@cleanup
2380+
def test_tick_space_size_0():
2381+
# allow font size to be zero, which affects ticks when there is
2382+
# no other text in the figure.
2383+
plt.plot([0, 1], [0, 1])
2384+
matplotlib.rcParams.update({'font.size': 0})
2385+
b = io.BytesIO()
2386+
plt.savefig(b, dpi=80, format='raw')
2387+
2388+
23792389
@image_comparison(baseline_images=['errorbar_basic', 'errorbar_mixed',
23802390
'errorbar_basic'])
23812391
def test_errorbar():

0 commit comments

Comments
 (0)