Skip to content

Commit c7ce914

Browse files
committed
Cleanup widget examples
1 parent 7a12f32 commit c7ce914

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

examples/widgets/cursor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
# Fixing random state for reproducibility
1313
np.random.seed(19680801)
1414

15-
fig = plt.figure(figsize=(8, 6))
16-
ax = fig.add_subplot(facecolor='#FFFFCC')
15+
fig, ax = plt.subplots(figsize=(8, 6))
1716

1817
x, y = 4*(np.random.rand(2, 100) - .5)
1918
ax.plot(x, y, 'o')

examples/widgets/span_selector.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,27 @@
1414
np.random.seed(19680801)
1515

1616
fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))
17-
ax1.set(facecolor='#FFFFCC')
1817

1918
x = np.arange(0.0, 5.0, 0.01)
2019
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))
2120

22-
ax1.plot(x, y, '-')
21+
ax1.plot(x, y)
2322
ax1.set_ylim(-2, 2)
24-
ax1.set_title('Press left mouse button and drag to test')
23+
ax1.set_title('Press left mouse button and drag '
24+
'to select a region in the top graph')
2525

26-
ax2.set(facecolor='#FFFFCC')
27-
line2, = ax2.plot(x, y, '-')
26+
line2, = ax2.plot([], [])
2827

2928

3029
def onselect(xmin, xmax):
3130
indmin, indmax = np.searchsorted(x, (xmin, xmax))
3231
indmax = min(len(x) - 1, indmax)
3332

34-
thisx = x[indmin:indmax]
35-
thisy = y[indmin:indmax]
36-
line2.set_data(thisx, thisy)
37-
ax2.set_xlim(thisx[0], thisx[-1])
38-
ax2.set_ylim(thisy.min(), thisy.max())
33+
region_x = x[indmin:indmax]
34+
region_y = y[indmin:indmax]
35+
line2.set_data(region_x, region_y)
36+
ax2.set_xlim(region_x[0], region_x[-1])
37+
ax2.set_ylim(region_y.min(), region_y.max())
3938
fig.canvas.draw()
4039

4140
#############################################################################
@@ -47,7 +46,7 @@ def onselect(xmin, xmax):
4746

4847

4948
span = SpanSelector(ax1, onselect, 'horizontal', useblit=True,
50-
rectprops=dict(alpha=0.5, facecolor='red'))
49+
rectprops=dict(alpha=0.5, facecolor='tab:blue'))
5150
# Set useblit=True on most backends for enhanced performance.
5251

5352

0 commit comments

Comments
 (0)