Skip to content

Commit 882a32b

Browse files
committed
Add what's new focs for button styling
1 parent b383eec commit 882a32b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Custom styling of Button widgets
2+
--------------------------------
3+
4+
Additional custom styling of button widget 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(1, 2, figsize=(5, 1), width_ratios=[1, 2])
13+
default = RadioButtons(ax[0], ['Apples', 'Oranges'])
14+
ax[0].set_title('Default')
15+
styled = RadioButtons(ax[1], ['Apples', 'Oranges'],
16+
label_props={'color': ['red', 'orange'],
17+
'fontsize': [20, 24]},
18+
radio_props={'edgecolor': ['red', 'orange'],
19+
'facecolor': ['darkred', 'darkorange']})
20+
ax[1].set_title('Stylized')
21+
22+
fig, ax = plt.subplots(1, 2, figsize=(5, 1), width_ratios=[1, 2])
23+
default = CheckButtons(ax[0], ['Apples', 'Oranges'],
24+
actives=[True, True])
25+
ax[0].set_title('Default')
26+
styled = CheckButtons(ax[1], ['Apples', 'Oranges'],
27+
actives=[True, True],
28+
label_props={'color': ['red', 'orange'],
29+
'fontsize': [20, 24]},
30+
frame_props={'color': ['red', 'orange']},
31+
check_props={'color': ['darkred', 'darkorange']})
32+
ax[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 to 's' marker, (label font size /
10211023
2)**2 size, black 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 'x' marker, (label font size /
10251029
2)**2 size, black color, and 1.0 linewidth.
1030+
1031+
.. versionadded:: 3.7
10261032
"""
10271033
super().__init__(ax)
10281034

@@ -1114,6 +1120,8 @@ def set_label_props(self, props):
11141120
"""
11151121
Set properties of the `.Text` labels.
11161122
1123+
.. versionadded:: 3.7
1124+
11171125
Parameters
11181126
----------
11191127
props : dict
@@ -1128,6 +1136,8 @@ def set_frame_props(self, props):
11281136
"""
11291137
Set properties of the check button frames.
11301138
1139+
.. versionadded:: 3.7
1140+
11311141
Parameters
11321142
----------
11331143
props : dict
@@ -1143,6 +1153,8 @@ def set_check_props(self, props):
11431153
"""
11441154
Set properties of the check button checks.
11451155
1156+
.. versionadded:: 3.7
1157+
11461158
Parameters
11471159
----------
11481160
props : dict
@@ -1617,6 +1629,8 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16171629
See the tutorial :doc:`/tutorials/advanced/blitting` for details.
16181630
label_props : dict or list of dict, optional
16191631
Dictionary of `.Text` properties to be used for the labels.
1632+
1633+
.. versionadded:: 3.7
16201634
radio_props : dict, optional
16211635
Dictionary of scatter `.Collection` properties to be used for the
16221636
radio buttons. Defaults to 'o' marker, (label font size / 2)**2
@@ -1626,6 +1640,8 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16261640
If a facecolor is supplied in *radio_props*, it will override
16271641
*activecolor*. This may be used to provide an active color per
16281642
button.
1643+
1644+
.. versionadded:: 3.7
16291645
"""
16301646
super().__init__(ax)
16311647

@@ -1726,6 +1742,8 @@ def set_label_props(self, props):
17261742
"""
17271743
Set properties of the `.Text` labels.
17281744
1745+
.. versionadded:: 3.7
1746+
17291747
Parameters
17301748
----------
17311749
props : dict
@@ -1740,6 +1758,8 @@ def set_radio_props(self, props):
17401758
"""
17411759
Set properties of the `.Text` labels.
17421760
1761+
.. versionadded:: 3.7
1762+
17431763
Parameters
17441764
----------
17451765
props : dict

0 commit comments

Comments
 (0)