Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,19 +2047,15 @@ def _update_offset_text_position(self, bboxes, bboxes2):
else:
bbox = mtransforms.Bbox.union(bboxes)
bottom = bbox.y0
self.offsetText.set_position(
(x, bottom - self.OFFSETTEXTPAD * self.figure.dpi / 72)
)
y = bottom - self.OFFSETTEXTPAD * self.figure.dpi / 72
else:
if not len(bboxes2):
top = self.axes.bbox.ymax
else:
bbox = mtransforms.Bbox.union(bboxes2)
top = bbox.y1
self.offsetText.set_va('top')
self.offsetText.set_position(
(x, top + self.OFFSETTEXTPAD * self.figure.dpi / 72)
)
y = top + self.OFFSETTEXTPAD * self.figure.dpi / 72
self.offsetText.set_position((x, y))

def get_text_heights(self, renderer):
"""
Expand Down Expand Up @@ -2102,10 +2098,12 @@ def set_ticks_position(self, position):
self.set_tick_params(which='both', top=True, labeltop=True,
bottom=False, labelbottom=False)
self._tick_position = 'top'
self.offsetText.set_verticalalignment('bottom')
elif position == 'bottom':
self.set_tick_params(which='both', top=False, labeltop=False,
bottom=True, labelbottom=True)
self._tick_position = 'bottom'
self.offsetText.set_verticalalignment('top')
elif position == 'both':
self.set_tick_params(which='both', top=True,
bottom=True)
Expand All @@ -2116,6 +2114,7 @@ def set_ticks_position(self, position):
self.set_tick_params(which='both', top=True, labeltop=False,
bottom=True, labelbottom=True)
self._tick_position = 'bottom'
self.offsetText.set_verticalalignment('top')
else:
assert False, "unhandled parameter not caught by _check_in_list"
self.stale = True
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4641,19 +4641,23 @@ def test_move_offsetlabel():
ax.plot(data)
fig.canvas.draw()
before = ax.yaxis.offsetText.get_position()
assert ax.yaxis.offsetText.get_horizontalalignment() == 'left'
ax.yaxis.tick_right()
fig.canvas.draw()
after = ax.yaxis.offsetText.get_position()
assert after[0] > before[0] and after[1] == before[1]
assert ax.yaxis.offsetText.get_horizontalalignment() == 'right'

fig, ax = plt.subplots()
ax.plot(data)
fig.canvas.draw()
before = ax.xaxis.offsetText.get_position()
assert ax.xaxis.offsetText.get_verticalalignment() == 'top'
ax.xaxis.tick_top()
fig.canvas.draw()
after = ax.xaxis.offsetText.get_position()
assert after[0] == before[0] and after[1] > before[1]
assert ax.xaxis.offsetText.get_verticalalignment() == 'bottom'


@image_comparison(['rc_spines.png'], savefig_kwarg={'dpi': 40})
Expand Down