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

Skip to content

Commit 9f3c6f4

Browse files
authored
Merge pull request #24262 from oscargus/tickspinefix
Fix issue with space allocated for single tick that should not be there
2 parents f69cb50 + 3804cdd commit 9f3c6f4

File tree

6 files changed

+86
-7
lines changed

6 files changed

+86
-7
lines changed

lib/matplotlib/spines.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ def get_window_extent(self, renderer=None):
152152
# make sure the location is updated so that transforms etc are correct:
153153
self._adjust_location()
154154
bb = super().get_window_extent(renderer=renderer)
155-
if self.axis is None:
155+
if self.axis is None or not self.axis.get_visible():
156156
return bb
157157
bboxes = [bb]
158-
tickstocheck = [self.axis.majorTicks[0]]
159-
if len(self.axis.minorTicks) > 1:
160-
# only pad for minor ticks if there are more than one
161-
# of them. There is always one...
162-
tickstocheck.append(self.axis.minorTicks[1])
163-
for tick in tickstocheck:
158+
drawn_ticks = self.axis._update_ticks()
159+
160+
major_tick = next(iter({*drawn_ticks} & {*self.axis.majorTicks}), None)
161+
minor_tick = next(iter({*drawn_ticks} & {*self.axis.minorTicks}), None)
162+
for tick in [major_tick, minor_tick]:
163+
if tick is None:
164+
continue
164165
bb0 = bb.frozen()
165166
tickl = tick._size
166167
tickdir = tick._tickdir
Binary file not shown.
Lines changed: 64 additions & 0 deletions
Loading

lib/matplotlib/tests/test_spines.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,17 @@ def test_label_without_ticks():
134134
spine.get_path()).get_extents()
135135
assert ax.xaxis.label.get_position()[1] < spinebbox.ymin, \
136136
"X-Axis label not below the spine"
137+
138+
139+
@image_comparison(['black_axes'])
140+
def test_spines_black_axes():
141+
# GitHub #18804
142+
plt.rcParams["savefig.pad_inches"] = 0
143+
plt.rcParams["savefig.bbox"] = 'tight'
144+
fig = plt.figure(0, figsize=(4, 4))
145+
ax = fig.add_axes((0, 0, 1, 1))
146+
ax.set_xticklabels([])
147+
ax.set_yticklabels([])
148+
ax.set_xticks([])
149+
ax.set_yticks([])
150+
ax.set_facecolor((0, 0, 0))

0 commit comments

Comments
 (0)