Skip to content

Commit c0cd944

Browse files
authored
Merge pull request matplotlib#8858 from dstansby/pylab-moves3
Pylab example moves 3
2 parents 87638e3 + d4021aa commit c0cd944

26 files changed

+72
-83
lines changed

doc/users/prev_whats_new/whats_new_1.0.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Additionally, he has contributed a new module :mod:`~matplotlib.tri` and
5858
helper function :func:`~matplotlib.pyplot.triplot` for creating and
5959
plotting unstructured triangular grids.
6060

61-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_triplot_demo_001.png
62-
:target: ../../gallery/pylab_examples/triplot_demo.html
61+
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_triplot_demo_001.png
62+
:target: ../../gallery/images_contours_and_fields/triplot_demo.html
6363
:align: center
6464
:scale: 50
6565

doc/users/prev_whats_new/whats_new_1.2.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ Ian Thomas extended :meth:`~matplotlib.pyplot.tripcolor` to allow one color
200200
value to be specified for each triangular face rather than for each point in
201201
a triangulation.
202202

203-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_tripcolor_demo_001.png
204-
:target: ../../gallery/pylab_examples/tripcolor_demo.html
203+
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_tripcolor_demo_001.png
204+
:target: ../../gallery/images_contours_and_fields/tripcolor_demo.html
205205
:align: center
206206
:scale: 50
207207

@@ -214,8 +214,8 @@ Phil Elson added support for hatching to
214214
:func:`~matplotlib.pyplot.contourf`, together with the ability
215215
to use a legend to identify contoured ranges.
216216

217-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_contourf_hatching_001.png
218-
:target: ../../gallery/pylab_examples/contourf_hatching.html
217+
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_contourf_hatching_001.png
218+
:target: ../../gallery/images_contours_and_fields/contourf_hatching.html
219219
:align: center
220220
:scale: 50
221221

@@ -227,8 +227,3 @@ Known issues in the matplotlib 1.2 release
227227
- When using the Qt4Agg backend with IPython 0.11 or later, the save
228228
dialog will not display. This should be fixed in a future version
229229
of IPython.
230-
231-
232-
233-
234-

doc/users/prev_whats_new/whats_new_1.3.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ perform mesh refinement and smooth contouring was also added
141141
implementing some basic tools for triangular mesh improvement was
142142
added (:class:`~matplotlib.tri.TriAnalyzer`).
143143

144-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_tricontour_smooth_user_001.png
145-
:target: ../../gallery/pylab_examples/tricontour_smooth_user.html
144+
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_tricontour_smooth_user_001.png
145+
:target: ../../gallery/images_contours_and_fields/tricontour_smooth_user.html
146146
:align: center
147147
:scale: 50
148148

@@ -400,9 +400,3 @@ matplotlib will now display a `RuntimeWarning` when too many figures
400400
have been opened at once. By default, this is displayed for 20 or
401401
more figures, but the exact number may be controlled using the
402402
``figure.max_open_warning`` rcParam.
403-
404-
405-
406-
407-
408-

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')

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
n = 12
1818
x = np.linspace(-1.5, 1.5, n)
19-
y = np.linspace(-1.5, 1.5, n*2)
19+
y = np.linspace(-1.5, 1.5, n * 2)
2020
X, Y = np.meshgrid(x, y)
2121
Qx = np.cos(Y) - np.cos(X)
2222
Qz = np.sin(Y) + np.sin(X)
2323
Qx = (Qx + 1.1)
24-
Z = np.sqrt(X**2 + Y**2)/5
24+
Z = np.sqrt(X**2 + Y**2) / 5
2525
Z = (Z - Z.min()) / (Z.max() - Z.min())
2626

2727
# The color array can include masked values:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ def compare(z, cmap, ve=1):
5959

6060
return fig
6161

62+
6263
if __name__ == '__main__':
6364
main()

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
min_radius = 0.25
2020
radii = np.linspace(min_radius, 0.95, n_radii)
2121

22-
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
22+
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
2323
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
24-
angles[:, 1::2] += math.pi/n_angles
24+
angles[:, 1::2] += math.pi / n_angles
2525

26-
x = (radii*np.cos(angles)).flatten()
27-
y = (radii*np.sin(angles)).flatten()
28-
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
26+
x = (radii * np.cos(angles)).flatten()
27+
y = (radii * np.sin(angles)).flatten()
28+
z = (np.cos(radii) * np.cos(angles * 3.0)).flatten()
2929

3030
# Create the Triangulation; no triangles so Delaunay triangulation created.
3131
triang = tri.Triangulation(x, y)
3232

3333
# Mask off unwanted triangles.
3434
xmid = x[triang.triangles].mean(axis=1)
3535
ymid = y[triang.triangles].mean(axis=1)
36-
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
36+
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
3737
triang.set_mask(mask)
3838

3939
# pcolor plot.
@@ -73,7 +73,7 @@
7373
y = np.degrees(xy[:, 1])
7474
x0 = -5
7575
y0 = 52
76-
z = np.exp(-0.01*((x - x0)*(x - x0) + (y - y0)*(y - y0)))
76+
z = np.exp(-0.01 * ((x - x0) * (x - x0) + (y - y0) * (y - y0)))
7777

7878
triangles = np.asarray([
7979
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
#-----------------------------------------------------------------------------
3636
def experiment_res(x, y):
3737
""" An analytic function representing experiment results """
38-
x = 2.*x
38+
x = 2. * x
3939
r1 = np.sqrt((0.5 - x)**2 + (0.5 - y)**2)
4040
theta1 = np.arctan2(0.5 - x, 0.5 - y)
4141
r2 = np.sqrt((-x - 0.2)**2 + (-y - 0.2)**2)
4242
theta2 = np.arctan2(-x - 0.2, -y - 0.2)
43-
z = (4*(np.exp((r1/10)**2) - 1)*30. * np.cos(3*theta1) +
44-
(np.exp((r2/10)**2) - 1)*30. * np.cos(5*theta2) +
45-
2*(x**2 + y**2))
46-
return (np.max(z) - z)/(np.max(z) - np.min(z))
43+
z = (4 * (np.exp((r1 / 10)**2) - 1) * 30. * np.cos(3 * theta1) +
44+
(np.exp((r2 / 10)**2) - 1) * 30. * np.cos(5 * theta2) +
45+
2 * (x**2 + y**2))
46+
return (np.max(z) - z) / (np.max(z) - np.min(z))
4747

4848
#-----------------------------------------------------------------------------
4949
# Generating the initial data test points and triangulation for the demo
@@ -76,7 +76,7 @@ def experiment_res(x, y):
7676

7777
# Some invalid data are masked out
7878
mask_init = np.zeros(ntri, dtype=np.bool)
79-
masked_tri = random_gen.randint(0, ntri, int(ntri*init_mask_frac))
79+
masked_tri = random_gen.randint(0, ntri, int(ntri * init_mask_frac))
8080
mask_init[masked_tri] = True
8181
tri.set_mask(mask_init)
8282

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def function_z(x, y):
2222
theta1 = np.arctan2(0.5 - x, 0.5 - y)
2323
r2 = np.sqrt((-x - 0.2)**2 + (-y - 0.2)**2)
2424
theta2 = np.arctan2(-x - 0.2, -y - 0.2)
25-
z = -(2*(np.exp((r1/10)**2) - 1)*30. * np.cos(7.*theta1) +
26-
(np.exp((r2/10)**2) - 1)*30. * np.cos(11.*theta2) +
27-
0.7*(x**2 + y**2))
28-
return (np.max(z) - z)/(np.max(z) - np.min(z))
25+
z = -(2 * (np.exp((r1 / 10)**2) - 1) * 30. * np.cos(7. * theta1) +
26+
(np.exp((r2 / 10)**2) - 1) * 30. * np.cos(11. * theta2) +
27+
0.7 * (x**2 + y**2))
28+
return (np.max(z) - z) / (np.max(z) - np.min(z))
2929

3030
#-----------------------------------------------------------------------------
3131
# Creating a Triangulation
@@ -36,12 +36,12 @@ def function_z(x, y):
3636
min_radius = 0.15
3737
radii = np.linspace(min_radius, 0.95, n_radii)
3838

39-
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
39+
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
4040
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
41-
angles[:, 1::2] += math.pi/n_angles
41+
angles[:, 1::2] += math.pi / n_angles
4242

43-
x = (radii*np.cos(angles)).flatten()
44-
y = (radii*np.sin(angles)).flatten()
43+
x = (radii * np.cos(angles)).flatten()
44+
y = (radii * np.sin(angles)).flatten()
4545
z = function_z(x, y)
4646

4747
# Now create the Triangulation.
@@ -52,7 +52,7 @@ def function_z(x, y):
5252
# Mask off unwanted triangles.
5353
xmid = x[triang.triangles].mean(axis=1)
5454
ymid = y[triang.triangles].mean(axis=1)
55-
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
55+
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
5656
triang.set_mask(mask)
5757

5858
#-----------------------------------------------------------------------------

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ngridy = 200
1919
x = np.random.uniform(-2, 2, npts)
2020
y = np.random.uniform(-2, 2, npts)
21-
z = x*np.exp(-x**2 - y**2)
21+
z = x * np.exp(-x**2 - y**2)
2222

2323
# griddata and contour.
2424
start = time.clock()
@@ -34,8 +34,8 @@
3434
plt.xlim(-2, 2)
3535
plt.ylim(-2, 2)
3636
plt.title('griddata and contour (%d points, %d grid points)' %
37-
(npts, ngridx*ngridy))
38-
print('griddata and contour seconds: %f' % (time.clock() - start))
37+
(npts, ngridx * ngridy))
38+
print('griddata and contour: %f seconds' % (time.clock() - start))
3939

4040
# tricontour.
4141
start = time.clock()
@@ -49,7 +49,7 @@
4949
plt.xlim(-2, 2)
5050
plt.ylim(-2, 2)
5151
plt.title('tricontour (%d points)' % npts)
52-
print('tricontour seconds: %f' % (time.clock() - start))
52+
print('tricontour: %f seconds' % (time.clock() - start))
5353

5454
plt.subplots_adjust(hspace=0.5)
5555

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
triang = mtri.Triangulation(x, y, triangles)
1818

1919
# Interpolate to regularly-spaced quad grid.
20-
z = np.cos(1.5*x)*np.cos(1.5*y)
20+
z = np.cos(1.5 * x) * np.cos(1.5 * y)
2121
xi, yi = np.meshgrid(np.linspace(0, 3, 20), np.linspace(0, 3, 20))
2222

2323
interp_lin = mtri.LinearTriInterpolator(triang, z)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
min_radius = 0.25
2020
radii = np.linspace(min_radius, 0.95, n_radii)
2121

22-
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
22+
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
2323
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
24-
angles[:, 1::2] += math.pi/n_angles
24+
angles[:, 1::2] += math.pi / n_angles
2525

26-
x = (radii*np.cos(angles)).flatten()
27-
y = (radii*np.sin(angles)).flatten()
28-
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
26+
x = (radii * np.cos(angles)).flatten()
27+
y = (radii * np.sin(angles)).flatten()
28+
z = (np.cos(radii) * np.cos(angles * 3.0)).flatten()
2929

3030
# Create the Triangulation; no triangles so Delaunay triangulation created.
3131
triang = tri.Triangulation(x, y)
3232

3333
# Mask off unwanted triangles.
3434
xmid = x[triang.triangles].mean(axis=1)
3535
ymid = y[triang.triangles].mean(axis=1)
36-
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
36+
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
3737
triang.set_mask(mask)
3838

3939
# tripcolor plot.
@@ -100,7 +100,8 @@
100100
ymid = y[triangles].mean(axis=1)
101101
x0 = -5
102102
y0 = 52
103-
zfaces = np.exp(-0.01*((xmid - x0)*(xmid - x0) + (ymid - y0)*(ymid - y0)))
103+
zfaces = np.exp(-0.01 * ((xmid - x0) * (xmid - x0) +
104+
(ymid - y0) * (ymid - y0)))
104105

105106
# Rather than create a Triangulation object, can simply pass x, y and triangles
106107
# arrays to tripcolor directly. It would be better to use a Triangulation

0 commit comments

Comments
 (0)