Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite43920d

Browse files
committed
Warn if activecolor and a facecolor are provided
1 parent9812cea commite43920d

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+
deftest_radio_button_active_conflict(ax):
1036+
withpytest.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+
assertmcolors.same_color(rb._buttons.get_facecolor(), ['green','none'])
1042+
1043+
10351044
@check_figures_equal(extensions=["png"])
10361045
deftest_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+
ifactivecolorisnotNone:
1623+
if'facecolor'inradio_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)

[8]ページ先頭

©2009-2025 Movatter.jp