Skip to content
Closed
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
10 changes: 9 additions & 1 deletion lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,16 @@ def set_position(self, position):
"'axes', or 'data' ")
self._position = position
self.set_transform(self.get_spine_transform())
if self.axis is not None:
if self.axis is not None and position != ('outward', 0.0):
major_labels = self.axis.get_majorticklabels()
minor_labels = self.axis.get_minorticklabels()
major_cols = [lab.get_color() for lab in major_labels]
minor_cols = [lab.get_color() for lab in minor_labels]
self.axis.reset_ticks()
for col, label in zip(major_cols, self.axis.get_majorticklabels()):
label.set_color(col)
for col, label in zip(minor_cols, self.axis.get_minorticklabels()):
label.set_color(col)
self.stale = True

def get_position(self):
Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,19 @@ def test_label_without_ticks():
spine.get_path()).get_extents()
assert ax.xaxis.label.get_position()[1] < spinebbox.ymin, \
"X-Axis label not below the spine"


@check_figures_equal(extensions=['png'])
def test_set_position_maintains_label_color(fig_test, fig_ref):
# set_position should not change the label color
ax = fig_test.subplots()
ax.plot([1, 2, 3])
for lab in ax.get_xticklabels():
lab.set_color("r")
ax.spines.left.set_position(("outward", 10))

ax = fig_ref.subplots()
ax.plot([1, 2, 3])
ax.spines.left.set_position(("outward", 10))
for lab in ax.get_xticklabels():
lab.set_color("r")