Add support for horizontal CheckButtons · matplotlib/matplotlib@b58dc7d · GitHub
Skip to content

Commit b58dc7d

Browse files
committed
Add support for horizontal CheckButtons
1 parent 035517e commit b58dc7d

4 files changed

Lines changed: 81 additions & 25 deletions

File tree

Lines changed: 11 additions & 5 deletions
4.73 KB
Loading

lib/matplotlib/tests/test_widgets.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,11 @@ def test_lasso_set_props(ax):
10411041
assert line.get_alpha() == 0.3
10421042

10431043

1044-
def test_CheckButtons(ax):
1044+
@pytest.mark.parametrize('orientation', ['vertical', 'horizontal'])
1045+
def test_CheckButtons(ax, orientation):
10451046
labels = ('a', 'b', 'c')
1046-
check = widgets.CheckButtons(ax, labels, (True, False, True))
1047+
check = widgets.CheckButtons(ax, labels, (True, False, True),
1048+
orientation=orientation)
10471049
assert check.get_status() == [True, False, True]
10481050
check.set_active(0)
10491051
assert check.get_status() == [False, False, True]
@@ -1110,28 +1112,54 @@ def test_RadioButtons(ax, orientation):
11101112

11111113
@image_comparison(['check_radio_buttons.png'], style='mpl20', remove_text=True)
11121114
def test_check_radio_buttons_image():
1113-
ax = get_ax()
1114-
fig = ax.figure
1115-
fig.subplots_adjust(left=0.3)
1115+
fig = plt.figure()
1116+
1117+
rb1 = widgets.RadioButtons(fig.add_axes((0.05, 0.7, 0.2, 0.15)),
1118+
('Radio 1', 'Radio 2', 'Radio 3'))
11161119

1117-
rax1 = fig.add_axes((0.05, 0.7, 0.2, 0.15))
1118-
rb1 = widgets.RadioButtons(rax1, ('Radio 1', 'Radio 2', 'Radio 3'))
1120+
rb2 = widgets.RadioButtons(fig.add_axes((0.3, 0.7, 0.6, 0.15)),
1121+
('Radio 1', 'Radio 2', 'Radio 3'),
1122+
orientation='horizontal')
11191123

1120-
rax2 = fig.add_axes((0.05, 0.5, 0.2, 0.15))
1121-
cb1 = widgets.CheckButtons(rax2, ('Check 1', 'Check 2', 'Check 3'),
1124+
cb1 = widgets.CheckButtons(fig.add_axes((0.05, 0.5, 0.2, 0.15)),
1125+
('Check 1', 'Check 2', 'Check 3'),
11221126
(False, True, True))
11231127

1124-
rax3 = fig.add_axes((0.05, 0.3, 0.2, 0.15))
1128+
cb2 = widgets.CheckButtons(fig.add_axes((0.3, 0.5, 0.6, 0.15)),
1129+
('Check 1', 'Check 2', 'Check 3'),
1130+
(False, True, True),
1131+
orientation='horizontal')
1132+
11251133
rb3 = widgets.RadioButtons(
1126-
rax3, ('Radio 1', 'Radio 2', 'Radio 3'),
1134+
fig.add_axes((0.05, 0.3, 0.2, 0.15)),
1135+
('Radio 1', 'Radio 2', 'Radio 3'),
1136+
label_props={'fontsize': [8, 12, 16],
1137+
'color': ['red', 'green', 'blue']},
1138+
radio_props={'edgecolor': ['red', 'green', 'blue'],
1139+
'facecolor': ['mistyrose', 'palegreen', 'lightblue']})
1140+
1141+
rb4 = widgets.RadioButtons(
1142+
fig.add_axes((0.3, 0.3, 0.6, 0.15)),
1143+
('Radio 1', 'Radio 2', 'Radio 3'),
1144+
orientation='horizontal',
11271145
label_props={'fontsize': [8, 12, 16],
11281146
'color': ['red', 'green', 'blue']},
11291147
radio_props={'edgecolor': ['red', 'green', 'blue'],
11301148
'facecolor': ['mistyrose', 'palegreen', 'lightblue']})
11311149

1132-
rax4 = fig.add_axes((0.05, 0.1, 0.2, 0.15))
1150+
cb3 = widgets.CheckButtons(
1151+
fig.add_axes((0.05, 0.1, 0.2, 0.15)),
1152+
('Check 1', 'Check 2', 'Check 3'), (False, True, True),
1153+
label_props={'fontsize': [8, 12, 16],
1154+
'color': ['red', 'green', 'blue']},
1155+
frame_props={'edgecolor': ['red', 'green', 'blue'],
1156+
'facecolor': ['mistyrose', 'palegreen', 'lightblue']},
1157+
check_props={'color': ['red', 'green', 'blue']})
1158+
11331159
cb4 = widgets.CheckButtons(
1134-
rax4, ('Check 1', 'Check 2', 'Check 3'), (False, True, True),
1160+
fig.add_axes((0.3, 0.1, 0.6, 0.15)),
1161+
('Check 1', 'Check 2', 'Check 3'), (False, True, True),
1162+
orientation='horizontal',
11351163
label_props={'fontsize': [8, 12, 16],
11361164
'color': ['red', 'green', 'blue']},
11371165
frame_props={'edgecolor': ['red', 'green', 'blue'],

lib/matplotlib/widgets.py

Lines changed: 29 additions & 7 deletions

0 commit comments

Comments
 (0)