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

Skip to content

Commit 088c816

Browse files
committed
Handle modification of RadioButtons.activecolor
1 parent 7aa6979 commit 088c816

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,17 @@ def test_radio_button_active_conflict(ax):
10431043
assert mcolors.same_color(rb._buttons.get_facecolor(), ['green', 'none'])
10441044

10451045

1046+
@check_figures_equal(extensions=['png'])
1047+
def test_radio_buttons_activecolor_change(fig_test, fig_ref):
1048+
widgets.RadioButtons(fig_ref.subplots(), ['tea', 'coffee'],
1049+
activecolor='green')
1050+
1051+
# Test property setter.
1052+
cb = widgets.RadioButtons(fig_test.subplots(), ['tea', 'coffee'],
1053+
activecolor='red')
1054+
cb.activecolor = 'green'
1055+
1056+
10461057
@check_figures_equal(extensions=["png"])
10471058
def test_check_buttons(fig_test, fig_ref):
10481059
widgets.CheckButtons(fig_test.subplots(), ["tea", "coffee"], [True, True])

lib/matplotlib/widgets.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16321632
else:
16331633
activecolor = 'blue' # Default.
16341634

1635-
self.activecolor = activecolor
1635+
self._activecolor = activecolor
16361636
self.value_selected = labels[active]
16371637

16381638
ax.set_xticks([])
@@ -1748,6 +1748,16 @@ def set_radio_props(self, props):
17481748
[activecolor if text.get_text() == self.value_selected else "none"
17491749
for text, activecolor in zip(self.labels, self._active_colors)])
17501750

1751+
@property
1752+
def activecolor(self):
1753+
return self._activecolor
1754+
1755+
@activecolor.setter
1756+
def activecolor(self, activecolor):
1757+
colors._check_color_like(activecolor=activecolor)
1758+
self._activecolor = activecolor
1759+
self.set_radio_props({'facecolor': activecolor})
1760+
17511761
def set_active(self, index):
17521762
"""
17531763
Select button with number *index*.

0 commit comments

Comments
 (0)