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

Skip to content

Commit c897f19

Browse files
committed
Move images, contours and fields from pylab_examples and clean
1 parent 454dbbb commit c897f19

22 files changed

Lines changed: 60 additions & 60 deletions
File renamed without changes.

examples/pylab_examples/contour_image.py renamed to examples/images_contours_and_fields/contour_image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
2929
Z = (Z1 - Z2) * 10
3030

31-
levels = np.arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation errors.
31+
# Boost the upper limit to avoid truncation errors.
32+
levels = np.arange(-2.0, 1.601, 0.4)
3233

3334
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
3435
cmap = cm.PRGn
@@ -40,9 +41,7 @@
4041
plt.subplot(2, 2, 1)
4142

4243
cset1 = plt.contourf(X, Y, Z, levels,
43-
cmap=cm.get_cmap(cmap, len(levels) - 1),
44-
norm=norm,
45-
)
44+
cmap=cm.get_cmap(cmap, len(levels) - 1), norm=norm)
4645
# It is not necessary, but for the colormap, we need only the
4746
# number of levels minus 1. To avoid discretization error, use
4847
# either this number or a large number such as the default (256).
@@ -94,7 +93,8 @@
9493
# This is intentional. The Z values are defined at the center of each
9594
# image pixel (each color block on the following subplot), so the
9695
# domain that is contoured does not extend beyond these pixel centers.
97-
im = plt.imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
96+
im = plt.imshow(Z, interpolation='nearest', extent=extent,
97+
cmap=cmap, norm=norm)
9898
v = plt.axis()
9999
plt.contour(Z, levels, colors='k', origin='image', extent=extent)
100100
plt.axis(v)

examples/pylab_examples/contour_label_demo.py renamed to examples/images_contours_and_fields/contour_label_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __repr__(self):
4848
else:
4949
return '%.1f' % self.__float__()
5050

51+
5152
# Recast levels to new class
5253
CS.levels = [nf(val) for val in CS.levels]
5354

examples/pylab_examples/contourf_demo.py renamed to examples/images_contours_and_fields/contourf_demo.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import matplotlib.pyplot as plt
99

1010
origin = 'lower'
11-
#origin = 'upper'
1211

1312
delta = 0.025
1413

@@ -21,13 +20,13 @@
2120
nr, nc = Z.shape
2221

2322
# put NaNs in one corner:
24-
Z[-nr//6:, -nc//6:] = np.nan
23+
Z[-nr // 6:, -nc // 6:] = np.nan
2524
# contourf will convert these to masked
2625

2726

2827
Z = np.ma.array(Z)
2928
# mask another corner:
30-
Z[:nr//6, :nc//6] = np.ma.masked
29+
Z[:nr // 6, :nc // 6] = np.ma.masked
3130

3231
# mask a circle in the middle:
3332
interior = np.sqrt((X**2) + (Y**2)) < 0.5
@@ -37,20 +36,14 @@
3736
# this is usually not such a good idea, because they don't
3837
# occur on nice boundaries, but we do it here for purposes
3938
# of illustration.
40-
CS = plt.contourf(X, Y, Z, 10,
41-
#[-1, -0.1, 0, 0.1],
42-
#alpha=0.5,
43-
cmap=plt.cm.bone,
44-
origin=origin)
39+
CS = plt.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin)
4540

4641
# Note that in the following, we explicitly pass in a subset of
4742
# the contour levels used for the filled contours. Alternatively,
4843
# We could pass in additional levels to provide extra resolution,
4944
# or leave out the levels kwarg to use all of the original levels.
5045

51-
CS2 = plt.contour(CS, levels=CS.levels[::2],
52-
colors='r',
53-
origin=origin)
46+
CS2 = plt.contour(CS, levels=CS.levels[::2], colors='r', origin=origin)
5447

5548
plt.title('Nonsense (3 masked regions)')
5649
plt.xlabel('word length anomaly')
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/pylab_examples/layer_images.py renamed to examples/images_contours_and_fields/layer_images.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212

1313
def func3(x, y):
14-
return (1 - x/2 + x**5 + y**3)*np.exp(-(x**2 + y**2))
14+
return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2))
15+
1516

1617
# make these smaller to increase the resolution
1718
dx, dy = 0.05, 0.05

examples/pylab_examples/multi_image.py renamed to examples/images_contours_and_fields/multi_image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
vmax = -1e40
3535
for i in range(Nr):
3636
for j in range(Nc):
37-
pos = [0.075 + j*1.1*w, 0.18 + i*1.2*h, w, h]
37+
pos = [0.075 + j * 1.1 * w, 0.18 + i * 1.2 * h, w, h]
3838
a = fig.add_axes(pos)
3939
if i > 0:
4040
a.set_xticklabels([])
@@ -64,6 +64,7 @@ def __call__(self, leader):
6464
self.follower.set_cmap(leader.get_cmap())
6565
self.follower.set_clim(leader.get_clim())
6666

67+
6768
norm = colors.Normalize(vmin=vmin, vmax=vmax)
6869
for i, im in enumerate(images):
6970
im.set_norm(norm)

examples/pylab_examples/pcolor_demo.py renamed to examples/images_contours_and_fields/pcolor_demo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
c = ax1.pcolor(Z, edgecolors='k', linewidths=4)
2929
ax1.set_title('thick edges')
3030

31+
fig.tight_layout()
3132
plt.show()
3233

3334
###############################################################################
@@ -94,7 +95,8 @@
9495
# A low hump with a spike coming out of the top right.
9596
# Needs to have z/colour axis on a log scale so we see both hump and spike.
9697
# linear scale only shows the spike.
97-
Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
98+
Z1 = (bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) +
99+
0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0))
98100

99101
fig, (ax0, ax1) = plt.subplots(2, 1)
100102

0 commit comments

Comments
 (0)