Skip to content

Commit e43920d

Browse files
committed
Warn if activecolor and a facecolor are provided
1 parent 9812cea commit e43920d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,15 @@ def test_radio_buttons_props(fig_test, fig_ref):
10321032
cb.set_radio_props({**radio_props, 's': (24 / 2)**2})
10331033

10341034

1035+
def test_radio_button_active_conflict(ax):
1036+
with pytest.warns(UserWarning,
1037+
match=r'Both the \*activecolor\* parameter'):
1038+
rb = widgets.RadioButtons(ax, ['tea', 'coffee'], activecolor='red',
1039+
radio_props={'facecolor': 'green'})
1040+
# *radio_props*' facecolor wins over *activecolor*
1041+
assert mcolors.same_color(rb._buttons.get_facecolor(), ['green', 'none'])
1042+
1043+
10351044
@check_figures_equal(extensions=["png"])
10361045
def test_check_buttons(fig_test, fig_ref):
10371046
widgets.CheckButtons(fig_test.subplots(), ["tea", "coffee"], [True, True])

lib/matplotlib/widgets.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ class RadioButtons(AxesWidget):
15841584
The label text of the currently selected button.
15851585
"""
15861586

1587-
def __init__(self, ax, labels, active=0, activecolor='blue', *,
1587+
def __init__(self, ax, labels, active=0, activecolor=None, *,
15881588
useblit=True, label_props=None, radio_props=None):
15891589
"""
15901590
Add radio buttons to an `~.axes.Axes`.
@@ -1598,12 +1598,8 @@ def __init__(self, ax, labels, active=0, activecolor='blue', *,
15981598
active : int
15991599
The index of the initially selected button.
16001600
activecolor : color
1601-
The color of the selected button.
1602-
1603-
.. note::
1604-
If a facecolor is supplied in *radio_props*, it will override
1605-
*activecolor*. This may be used to provide an active color per
1606-
button.
1601+
The color of the selected button. The default is ``'blue'`` if not
1602+
specified here or in *radio_props*.
16071603
useblit : bool, default: True
16081604
Use blitting for faster drawing if supported by the backend.
16091605
See the tutorial :doc:`/tutorials/advanced/blitting` for details.
@@ -1620,6 +1616,18 @@ def __init__(self, ax, labels, active=0, activecolor='blue', *,
16201616
button.
16211617
"""
16221618
super().__init__(ax)
1619+
1620+
radio_props = cbook.normalize_kwargs(radio_props,
1621+
collections.PathCollection)
1622+
if activecolor is not None:
1623+
if 'facecolor' in radio_props:
1624+
_api.warn_external(
1625+
'Both the *activecolor* parameter and the *facecolor* '
1626+
'key in the *radio_props* parameter has been specified. '
1627+
'*activecolor* will be ignored.')
1628+
else:
1629+
activecolor = 'blue' # Default.
1630+
16231631
self.activecolor = activecolor
16241632
self.value_selected = labels[active]
16251633

@@ -1645,7 +1653,7 @@ def __init__(self, ax, labels, active=0, activecolor='blue', *,
16451653
's': text_size**2,
16461654
'facecolor': activecolor,
16471655
'edgecolor': 'black',
1648-
**cbook.normalize_kwargs(radio_props, collections.PathCollection),
1656+
**radio_props,
16491657
'transform': ax.transAxes,
16501658
'animated': self._useblit,
16511659
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy