Skip to content

Commit d9b5b4e

Browse files
authored
Merge pull request #10780 from TeamChillUTSC/4429-radio-btn-scale
Fix scaling of RadioButtons
2 parents cc44f57 + 1b3a180 commit d9b5b4e

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

lib/matplotlib/tests/test_widgets.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def onselect(epress, erelease):
9090

9191
if kwargs.get('drawtype', None) not in ['line', 'none']:
9292
assert_allclose(tool.geometry,
93-
[[100., 100, 199, 199, 100], [100, 199, 199, 100, 100]],
94-
err_msg=tool.geometry)
93+
[[100., 100, 199, 199, 100],
94+
[100, 199, 199, 100, 100]],
95+
err_msg=tool.geometry)
9596

9697
assert ax._got_onselect
9798

@@ -118,40 +119,41 @@ def onselect(epress, erelease):
118119

119120
# drag the rectangle
120121
do_event(tool, 'press', xdata=10, ydata=10, button=1,
121-
key=' ')
122+
key=' ')
123+
122124
do_event(tool, 'onmove', xdata=30, ydata=30, button=1)
123125
do_event(tool, 'release', xdata=30, ydata=30, button=1)
124126
assert tool.extents == (120, 170, 120, 170)
125127

126128
# create from center
127129
do_event(tool, 'on_key_press', xdata=100, ydata=100, button=1,
128-
key='control')
130+
key='control')
129131
do_event(tool, 'press', xdata=100, ydata=100, button=1)
130132
do_event(tool, 'onmove', xdata=125, ydata=125, button=1)
131133
do_event(tool, 'release', xdata=125, ydata=125, button=1)
132134
do_event(tool, 'on_key_release', xdata=100, ydata=100, button=1,
133-
key='control')
135+
key='control')
134136
assert tool.extents == (75, 125, 75, 125)
135137

136138
# create a square
137139
do_event(tool, 'on_key_press', xdata=10, ydata=10, button=1,
138-
key='shift')
140+
key='shift')
139141
do_event(tool, 'press', xdata=10, ydata=10, button=1)
140142
do_event(tool, 'onmove', xdata=35, ydata=30, button=1)
141143
do_event(tool, 'release', xdata=35, ydata=30, button=1)
142144
do_event(tool, 'on_key_release', xdata=10, ydata=10, button=1,
143-
key='shift')
145+
key='shift')
144146
extents = [int(e) for e in tool.extents]
145147
assert extents == [10, 35, 10, 34]
146148

147149
# create a square from center
148150
do_event(tool, 'on_key_press', xdata=100, ydata=100, button=1,
149-
key='ctrl+shift')
151+
key='ctrl+shift')
150152
do_event(tool, 'press', xdata=100, ydata=100, button=1)
151153
do_event(tool, 'onmove', xdata=125, ydata=130, button=1)
152154
do_event(tool, 'release', xdata=125, ydata=130, button=1)
153155
do_event(tool, 'on_key_release', xdata=100, ydata=100, button=1,
154-
key='ctrl+shift')
156+
key='ctrl+shift')
155157
extents = [int(e) for e in tool.extents]
156158
assert extents == [70, 129, 70, 130]
157159

@@ -261,7 +263,7 @@ def test_CheckButtons():
261263

262264

263265
@image_comparison(baseline_images=['check_radio_buttons'], extensions=['png'],
264-
style='default')
266+
style='mpl20', remove_text=True)
265267
def test_check_radio_buttons_image():
266268
get_ax()
267269
plt.subplots_adjust(left=0.3)
@@ -272,6 +274,15 @@ def test_check_radio_buttons_image():
272274
(False, True, True))
273275

274276

277+
@image_comparison(baseline_images=['check_bunch_of_radio_buttons'],
278+
style='mpl20', extensions=['png'], remove_text=True)
279+
def test_check_bunch_of_radio_buttons():
280+
rax = plt.axes([0.05, 0.1, 0.15, 0.7])
281+
widgets.RadioButtons(rax, ('B1', 'B2', 'B3', 'B4', 'B5', 'B6',
282+
'B7', 'B8', 'B9', 'B10', 'B11', 'B12',
283+
'B13', 'B14', 'B15'))
284+
285+
275286
def test_slider_slidermin_slidermax_invalid():
276287
fig, ax = plt.subplots()
277288
# test min/max with floats

lib/matplotlib/widgets.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,13 @@ def __init__(self, ax, labels, active=0, activecolor='blue'):
981981
cnt = 0
982982
axcolor = ax.get_facecolor()
983983

984+
# scale the radius of the circle with the spacing between each one
985+
circle_radius = (dy / 2) - 0.01
986+
987+
# defaul to hard-coded value if the radius becomes too large
988+
if(circle_radius > 0.05):
989+
circle_radius = 0.05
990+
984991
self.labels = []
985992
self.circles = []
986993
for y, label in zip(ys, labels):
@@ -994,7 +1001,7 @@ def __init__(self, ax, labels, active=0, activecolor='blue'):
9941001
else:
9951002
facecolor = axcolor
9961003

997-
p = Circle(xy=(0.15, y), radius=0.05, edgecolor='black',
1004+
p = Circle(xy=(0.15, y), radius=circle_radius, edgecolor='black',
9981005
facecolor=facecolor, transform=ax.transAxes)
9991006

10001007
self.labels.append(t)

0 commit comments

Comments
 (0)