Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74842be

Browse files
committed
*Buttons: use a semi-public self._buttons_ys variable
1 parent 4ca5e0c commit 74842be

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

lib/matplotlib/widgets.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,14 +1185,14 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
11851185

11861186
self._useblit = useblit
11871187

1188-
ys = np.linspace(1, 0, len(labels)+2)[1:-1]
1188+
self._buttons_ys = np.linspace(1, 0, len(labels)+2)[1:-1]
11891189

11901190
label_props = _expand_text_props(label_props)
11911191
self.labels = [
11921192
ax.text(0.25, y, label, transform=ax.transAxes,
11931193
horizontalalignment="left", verticalalignment="center",
11941194
**props)
1195-
for y, label, props in zip(ys, labels, label_props)]
1195+
for y, label, props in zip(self._buttons_ys, labels, label_props)]
11961196
text_size = np.array([text.get_fontsize() for text in self.labels]) / 2
11971197

11981198
frame_props = {
@@ -1204,7 +1204,11 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
12041204
}
12051205
frame_props.setdefault('facecolor', frame_props.get('color', 'none'))
12061206
frame_props.setdefault('edgecolor', frame_props.pop('color', 'black'))
1207-
self._frames = ax.scatter([0.15] * len(ys), ys, **frame_props)
1207+
self._frames = ax.scatter(
1208+
[0.15] * len(self._buttons_ys),
1209+
self._buttons_ys,
1210+
**frame_props,
1211+
)
12081212
check_props = {
12091213
'linewidth': 1,
12101214
's': text_size**2,
@@ -1217,7 +1221,11 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
12171221
# overhead on unsupported backends.
12181222
}
12191223
check_props.setdefault('facecolor', check_props.pop('color', 'black'))
1220-
self._buttons = ax.scatter([0.15] * len(ys), ys, **check_props)
1224+
self._buttons = ax.scatter(
1225+
[0.15] * len(self._buttons_ys),
1226+
self._buttons_ys,
1227+
**check_props
1228+
)
12211229
# The user may have passed custom colours in check_props, so we need to
12221230
# create the checks (above), and modify the visibility after getting
12231231
# whatever the user set.
@@ -1715,7 +1723,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
17151723
ax.set_yticks([])
17161724
ax.set_navigate(False)
17171725

1718-
ys = np.linspace(1, 0, len(labels) + 2)[1:-1]
1726+
self._buttons_ys = np.linspace(1, 0, len(labels) + 2)[1:-1]
17191727

17201728
self._useblit = useblit
17211729

@@ -1724,7 +1732,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
17241732
ax.text(0.25, y, label, transform=ax.transAxes,
17251733
horizontalalignment="left", verticalalignment="center",
17261734
**props)
1727-
for y, label, props in zip(ys, labels, label_props)]
1735+
for y, label, props in zip(self._buttons_ys, labels, label_props)]
17281736
text_size = np.array([text.get_fontsize() for text in self.labels]) / 2
17291737

17301738
radio_props = {
@@ -1741,7 +1749,11 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
17411749
radio_props.setdefault('edgecolor', radio_props.get('color', 'black'))
17421750
radio_props.setdefault('facecolor',
17431751
radio_props.pop('color', activecolor))
1744-
self._buttons = ax.scatter([.15] * len(ys), ys, **radio_props)
1752+
self._buttons = ax.scatter(
1753+
[.15] * len(self._buttons_ys),
1754+
self._buttons_ys,
1755+
**radio_props,
1756+
)
17451757
# The user may have passed custom colours in radio_props, so we need to
17461758
# create the radios, and modify the visibility after getting whatever
17471759
# the user set.

0 commit comments

Comments
 (0)