Skip to content

Commit 21a27ae

Browse files
committed
Add what's new focs for button styling
1 parent 088c816 commit 21a27ae

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Custom styling of button widgets
2+
--------------------------------
3+
4+
Additional custom styling of button widgets may be achieved via the
5+
*label_props* and *radio_props* arguments to `.RadioButtons`; and the
6+
*label_props*, *frame_props*, and *check_props* arguments to `.CheckButtons`.
7+
8+
.. plot::
9+
10+
from matplotlib.widgets import CheckButtons, RadioButtons
11+
12+
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(5, 2), width_ratios=[1, 2])
13+
default_rb = RadioButtons(ax[0, 0], ['Apples', 'Oranges'])
14+
styled_rb = RadioButtons(ax[0, 1], ['Apples', 'Oranges'],
15+
label_props={'color': ['red', 'orange'],
16+
'fontsize': [16, 20]},
17+
radio_props={'edgecolor': ['red', 'orange'],
18+
'facecolor': ['mistyrose', 'peachpuff']})
19+
20+
default_cb = CheckButtons(ax[1, 0], ['Apples', 'Oranges'],
21+
actives=[True, True])
22+
styled_cb = CheckButtons(ax[1, 1], ['Apples', 'Oranges'],
23+
actives=[True, True],
24+
label_props={'color': ['red', 'orange'],
25+
'fontsize': [16, 20]},
26+
frame_props={'edgecolor': ['red', 'orange'],
27+
'facecolor': ['mistyrose', 'peachpuff']},
28+
check_props={'color': ['darkred', 'darkorange']})
29+
30+
ax[0, 0].set_title('Default')
31+
ax[0, 1].set_title('Stylized')

lib/matplotlib/widgets.py

+20
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,20 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
10151015
See the tutorial :doc:`/tutorials/advanced/blitting` for details.
10161016
label_props : dict, optional
10171017
Dictionary of `.Text` properties to be used for the labels.
1018+
1019+
.. versionadded:: 3.7
10181020
frame_props : dict, optional
10191021
Dictionary of scatter `.Collection` properties to be used for the
10201022
check button frame. Defaults (label font size / 2)**2 size, black
10211023
edgecolor, no facecolor, and 1.0 linewidth.
1024+
1025+
.. versionadded:: 3.7
10221026
check_props : dict, optional
10231027
Dictionary of scatter `.Collection` properties to be used for the
10241028
check button check. Defaults to (label font size / 2)**2 size,
10251029
black color, and 1.0 linewidth.
1030+
1031+
.. versionadded:: 3.7
10261032
"""
10271033
super().__init__(ax)
10281034

@@ -1120,6 +1126,8 @@ def set_label_props(self, props):
11201126
"""
11211127
Set properties of the `.Text` labels.
11221128
1129+
.. versionadded:: 3.7
1130+
11231131
Parameters
11241132
----------
11251133
props : dict
@@ -1134,6 +1142,8 @@ def set_frame_props(self, props):
11341142
"""
11351143
Set properties of the check button frames.
11361144
1145+
.. versionadded:: 3.7
1146+
11371147
Parameters
11381148
----------
11391149
props : dict
@@ -1149,6 +1159,8 @@ def set_check_props(self, props):
11491159
"""
11501160
Set properties of the check button checks.
11511161
1162+
.. versionadded:: 3.7
1163+
11521164
Parameters
11531165
----------
11541166
props : dict
@@ -1606,6 +1618,8 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16061618
See the tutorial :doc:`/tutorials/advanced/blitting` for details.
16071619
label_props : dict or list of dict, optional
16081620
Dictionary of `.Text` properties to be used for the labels.
1621+
1622+
.. versionadded:: 3.7
16091623
radio_props : dict, optional
16101624
Dictionary of scatter `.Collection` properties to be used for the
16111625
radio buttons. Defaults to (label font size / 2)**2 size, black
@@ -1615,6 +1629,8 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16151629
If a facecolor is supplied in *radio_props*, it will override
16161630
*activecolor*. This may be used to provide an active color per
16171631
button.
1632+
1633+
.. versionadded:: 3.7
16181634
"""
16191635
super().__init__(ax)
16201636

@@ -1716,6 +1732,8 @@ def set_label_props(self, props):
17161732
"""
17171733
Set properties of the `.Text` labels.
17181734
1735+
.. versionadded:: 3.7
1736+
17191737
Parameters
17201738
----------
17211739
props : dict
@@ -1730,6 +1748,8 @@ def set_radio_props(self, props):
17301748
"""
17311749
Set properties of the `.Text` labels.
17321750
1751+
.. versionadded:: 3.7
1752+
17331753
Parameters
17341754
----------
17351755
props : dict

0 commit comments

Comments
 (0)