Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c9e1fd

Browse filesBrowse files
committed
Handle modification of RadioButtons.activecolor
1 parent 1a77aa6 commit 5c9e1fd
Copy full SHA for 5c9e1fd

File tree

Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed

‎lib/matplotlib/tests/test_widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_widgets.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,17 @@ def test_radio_button_active_conflict(ax):
10601060
assert mcolors.same_color(rb._buttons.get_facecolor(), ['green', 'none'])
10611061

10621062

1063+
@check_figures_equal(extensions=['png'])
1064+
def test_radio_buttons_activecolor_change(fig_test, fig_ref):
1065+
widgets.RadioButtons(fig_ref.subplots(), ['tea', 'coffee'],
1066+
activecolor='green')
1067+
1068+
# Test property setter.
1069+
cb = widgets.RadioButtons(fig_test.subplots(), ['tea', 'coffee'],
1070+
activecolor='red')
1071+
cb.activecolor = 'green'
1072+
1073+
10631074
@check_figures_equal(extensions=["png"])
10641075
def test_check_buttons(fig_test, fig_ref):
10651076
widgets.CheckButtons(fig_test.subplots(), ["tea", "coffee"], [True, True])

‎lib/matplotlib/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/widgets.py
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16341634
else:
16351635
activecolor = 'blue' # Default.
16361636

1637-
self.activecolor = activecolor
1637+
self._activecolor = activecolor
16381638
self.value_selected = labels[active]
16391639

16401640
ax.set_xticks([])
@@ -1750,6 +1750,21 @@ def set_radio_props(self, props):
17501750
[activecolor if text.get_text() == self.value_selected else "none"
17511751
for text, activecolor in zip(self.labels, self._active_colors)])
17521752

1753+
@property
1754+
def activecolor(self):
1755+
return self._activecolor
1756+
1757+
@activecolor.setter
1758+
def activecolor(self, activecolor):
1759+
colors._check_color_like(activecolor=activecolor)
1760+
self._activecolor = activecolor
1761+
self.set_radio_props({'facecolor': activecolor})
1762+
# Make sure the deprecated version is updated.
1763+
# Remove once circles is removed.
1764+
labels = [label.get_text() for label in self.labels]
1765+
with cbook._setattr_cm(self, eventson=False):
1766+
self.set_active(labels.index(self.value_selected))
1767+
17531768
def set_active(self, index):
17541769
"""
17551770
Select button with number *index*.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.