8000 Merge pull request #14593 from anntzer/secondarycolor · matplotlib/matplotlib@a861b8a · GitHub
[go: up one dir, main page]

Skip to content

Commit a861b8a

Browse files
authored
Merge pull request #14593 from anntzer/secondarycolor
Simplify SecondaryAxis.set_color.
2 parents f7bdfd3 + cb8f490 commit a861b8a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,12 @@ def set_color(self, color):
235235
----------
236236
color : color
237237
"""
238-
if self._orientation == 'x':
239-
self.tick_params(axis='x', colors=color)
240-
self.spines.bottom.set_color(color)
241-
self.spines.top.set_color(color)
242-
self.xaxis.label.set_color(color)
243-
else: # 'y'
244-
self.tick_params(axis='y', colors=color)
245-
self.spines.left.set_color(color)
246-
self.spines.right.set_color(color)
247-
self.yaxis.label.set_color(color)
238+
axis = self._axis_map[self._orientation]
239+
axis.set_tick_params(colors=color)
240+
for spine in self.spines.values():
241+
if spine.axis is axis:
242+
spine.set_color(color)
243+
axis.label.set_color(color)
248244

249245

250246
_secax_docstring = '''

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8784,3 +8784,13 @@ def test_tick_param_labelfont():
87848784
plt.title('Title in sans-serif')
87858785
for text in ax.get_xticklabels():
87868786
assert text.get_fontfamily()[0] == 'monospace'
8787+
8788+
8789+
def test_set_secondary_axis_color():
8790+
fig, ax = plt.subplots()
8791+
sax = ax.secondary_xaxis("top", color="red")
8792+
assert mcolors.same_color(sax.spines["bottom"].get_edgecolor(), "red")
8793+
assert mcolors.same_color(sax.spines["top"].get_edgecolor(), "red")
8794+
assert mcolors.same_color(sax.xaxis.get_tick_params()["color"], "red")
8795+
assert mcolors.same_color(sax.xaxis.get_tick_params()["labelcolor"], "red")
8796+
assert mcolors.same_color(sax.xaxis.label.get_color(), "red")

0 commit comments

Comments
 (0)
0