Skip to content

Pylab example moves 3 #8858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/users/prev_whats_new/whats_new_1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Additionally, he has contributed a new module :mod:`~matplotlib.tri` and
helper function :func:`~matplotlib.pyplot.triplot` for creating and
plotting unstructured triangular grids.

.. figure:: ../../gallery/pylab_examples/images/sphx_glr_triplot_demo_001.png
:target: ../../gallery/pylab_examples/triplot_demo.html
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_triplot_demo_001.png
:target: ../../gallery/images_contours_and_fields/triplot_demo.html
:align: center
:scale: 50

Expand Down
13 changes: 4 additions & 9 deletions doc/users/prev_whats_new/whats_new_1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ Ian Thomas extended :meth:`~matplotlib.pyplot.tripcolor` to allow one color
value to be specified for each triangular face rather than for each point in
a triangulation.

.. figure:: ../../gallery/pylab_examples/images/sphx_glr_tripcolor_demo_001.png
:target: ../../gallery/pylab_examples/tripcolor_demo.html
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_tripcolor_demo_001.png
:target: ../../gallery/images_contours_and_fields/tripcolor_demo.html
:align: center
:scale: 50

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

.. figure:: ../../gallery/pylab_examples/images/sphx_glr_contourf_hatching_001.png
:target: ../../gallery/pylab_examples/contourf_hatching.html
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_contourf_hatching_001.png
:target: ../../gallery/images_contours_and_fields/contourf_hatching.html
:align: center
:scale: 50

Expand All @@ -227,8 +227,3 @@ Known issues in the matplotlib 1.2 release
- When using the Qt4Agg backend with IPython 0.11 or later, the save
dialog will not display. This should be fixed in a future version
of IPython.





10 changes: 2 additions & 8 deletions doc/users/prev_whats_new/whats_new_1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ perform mesh refinement and smooth contouring was also added
implementing some basic tools for triangular mesh improvement was
added (:class:`~matplotlib.tri.TriAnalyzer`).

.. figure:: ../../gallery/pylab_examples/images/sphx_glr_tricontour_smooth_user_001.png
:target: ../../gallery/pylab_examples/tricontour_smooth_user.html
.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_tricontour_smooth_user_001.png
:target: ../../gallery/images_contours_and_fields/tricontour_smooth_user.html
:align: center
:scale: 50

Expand Down Expand Up @@ -400,9 +400,3 @@ matplotlib will now display a `RuntimeWarning` when too many figures
have been opened at once. By default, this is displayed for 20 or
more figures, but the exact number may be controlled using the
``figure.max_open_warning`` rcParam.






Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = (Z1 - Z2) * 10

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

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

cset1 = plt.contourf(X, Y, Z, levels,
cmap=cm.get_cmap(cmap, len(levels) - 1),
norm=norm,
)
cmap=cm.get_cmap(cmap, len(levels) - 1), norm=norm)
# It is not necessary, but for the colormap, we need only the
# number of levels minus 1. To avoid discretization error, use
# either this number or a large number such as the default (256).
Expand Down Expand Up @@ -94,7 +93,8 @@
# This is intentional. The Z values are defined at the center of each
# image pixel (each color block on the following subplot), so the
# domain that is contoured does not extend beyond these pixel centers.
im = plt.imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
im = plt.imshow(Z, interpolation='nearest', extent=extent,
cmap=cmap, norm=norm)
v = plt.axis()
plt.contour(Z, levels, colors='k', origin='image', extent=extent)
plt.axis(v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __repr__(self):
else:
return '%.1f' % self.__float__()


# Recast levels to new class
CS.levels = [nf(val) for val in CS.levels]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import matplotlib.pyplot as plt

origin = 'lower'
#origin = 'upper'

delta = 0.025

Expand All @@ -21,13 +20,13 @@
nr, nc = Z.shape

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


Z = np.ma.array(Z)
# mask another corner:
Z[:nr//6, :nc//6] = np.ma.masked
Z[:nr // 6, :nc // 6] = np.ma.masked

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

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

CS2 = plt.contour(CS, levels=CS.levels[::2],
colors='r',
origin=origin)
CS2 = plt.contour(CS, levels=CS.levels[::2], colors='r', origin=origin)

plt.title('Nonsense (3 masked regions)')
plt.xlabel('word length anomaly')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@


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


# make these smaller to increase the resolution
dx, dy = 0.05, 0.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
vmax = -1e40
for i in range(Nr):
for j in range(Nc):
pos = [0.075 + j*1.1*w, 0.18 + i*1.2*h, w, h]
pos = [0.075 + j * 1.1 * w, 0.18 + i * 1.2 * h, w, h]
a = fig.add_axes(pos)
if i > 0:
a.set_xticklabels([])
Expand Down Expand Up @@ -64,6 +64,7 @@ def __call__(self, leader):
self.follower.set_cmap(leader.get_cmap())
self.follower.set_clim(leader.get_clim())


norm = colors.Normalize(vmin=vmin, vmax=vmax)
for i, im in enumerate(images):
im.set_norm(norm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
c = ax1.pcolor(Z, edgecolors='k', linewidths=4)
ax1.set_title('thick edges')

fig.tight_layout()
plt.show()

###############################################################################
Expand Down Expand Up @@ -94,7 +95,8 @@
# A low hump with a spike coming out of the top right.
# Needs to have z/colour axis on a log scale so we see both hump and spike.
# linear scale only shows the spike.
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)
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))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

n = 12
x = np.linspace(-1.5, 1.5, n)
y = np.linspace(-1.5, 1.5, n*2)
y = np.linspace(-1.5, 1.5, n * 2)
X, Y = np.meshgrid(x, y)
Qx = np.cos(Y) - np.cos(X)
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.sqrt(X**2 + Y**2)/5
Z = np.sqrt(X**2 + Y**2) / 5
Z = (Z - Z.min()) / (Z.max() - Z.min())

# The color array can include masked values:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ def compare(z, cmap, ve=1):

return fig


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)

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

x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
x = (radii * np.cos(angles)).flatten()
y = (radii * np.sin(angles)).flatten()
z = (np.cos(radii) * np.cos(angles * 3.0)).flatten()

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

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

# pcolor plot.
Expand Down Expand Up @@ -73,7 +73,7 @@
y = np.degrees(xy[:, 1])
x0 = -5
y0 = 52
z = np.exp(-0.01*((x - x0)*(x - x0) + (y - y0)*(y - y0)))
z = np.exp(-0.01 * ((x - x0) * (x - x0) + (y - y0) * (y - y0)))

triangles = np.asarray([
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
#-----------------------------------------------------------------------------
def experiment_res(x, y):
""" An analytic function representing experiment results """
x = 2.*x
x = 2. * x
r1 = np.sqrt((0.5 - x)**2 + (0.5 - y)**2)
theta1 = np.arctan2(0.5 - x, 0.5 - y)
r2 = np.sqrt((-x - 0.2)**2 + (-y - 0.2)**2)
theta2 = np.arctan2(-x - 0.2, -y - 0.2)
z = (4*(np.exp((r1/10)**2) - 1)*30. * np.cos(3*theta1) +
(np.exp((r2/10)**2) - 1)*30. * np.cos(5*theta2) +
2*(x**2 + y**2))
return (np.max(z) - z)/(np.max(z) - np.min(z))
z = (4 * (np.exp((r1 / 10)**2) - 1) * 30. * np.cos(3 * theta1) +
(np.exp((r2 / 10)**2) - 1) * 30. * np.cos(5 * theta2) +
2 * (x**2 + y**2))
return (np.max(z) - z) / (np.max(z) - np.min(z))

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

# Some invalid data are masked out
mask_init = np.zeros(ntri, dtype=np.bool)
masked_tri = random_gen.randint(0, ntri, int(ntri*init_mask_frac))
masked_tri = random_gen.randint(0, ntri, int(ntri * init_mask_frac))
mask_init[masked_tri] = True
tri.set_mask(mask_init)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def function_z(x, y):
theta1 = np.arctan2(0.5 - x, 0.5 - y)
r2 = np.sqrt((-x - 0.2)**2 + (-y - 0.2)**2)
theta2 = np.arctan2(-x - 0.2, -y - 0.2)
z = -(2*(np.exp((r1/10)**2) - 1)*30. * np.cos(7.*theta1) +
(np.exp((r2/10)**2) - 1)*30. * np.cos(11.*theta2) +
0.7*(x**2 + y**2))
return (np.max(z) - z)/(np.max(z) - np.min(z))
z = -(2 * (np.exp((r1 / 10)**2) - 1) * 30. * np.cos(7. * theta1) +
(np.exp((r2 / 10)**2) - 1) * 30. * np.cos(11. * theta2) +
0.7 * (x**2 + y**2))
return (np.max(z) - z) / (np.max(z) - np.min(z))

#-----------------------------------------------------------------------------
# Creating a Triangulation
Expand All @@ -36,12 +36,12 @@ def function_z(x, y):
min_radius = 0.15
radii = np.linspace(min_radius, 0.95, n_radii)

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

x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
x = (radii * np.cos(angles)).flatten()
y = (radii * np.sin(angles)).flatten()
z = function_z(x, y)

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

#-----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ngridy = 200
x = np.random.uniform(-2, 2, npts)
y = np.random.uniform(-2, 2, npts)
z = x*np.exp(-x**2 - y**2)
z = x * np.exp(-x**2 - y**2)

# griddata and contour.
start = time.clock()
Expand All @@ -34,8 +34,8 @@
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.title('griddata and contour (%d points, %d grid points)' %
(npts, ngridx*ngridy))
print('griddata and contour seconds: %f' % (time.clock() - start))
(npts, ngridx * ngridy))
print('griddata and contour: %f seconds' % (time.clock() - start))

# tricontour.
start = time.clock()
Expand All @@ -49,7 +49,7 @@
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.title('tricontour (%d points)' % npts)
print('tricontour seconds: %f' % (time.clock() - start))
print('tricontour: %f seconds' % (time.clock() - start))

plt.subplots_adjust(hspace=0.5)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
triang = mtri.Triangulation(x, y, triangles)

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

interp_lin = mtri.LinearTriInterpolator(triang, z)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)

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

x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
x = (radii * np.cos(angles)).flatten()
y = (radii * np.sin(angles)).flatten()
z = (np.cos(radii) * np.cos(angles * 3.0)).flatten()

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

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

# tripcolor plot.
Expand Down Expand Up @@ -100,7 +100,8 @@
ymid = y[triangles].mean(axis=1)
x0 = -5
y0 = 52
zfaces = np.exp(-0.01*((xmid - x0)*(xmid - x0) + (ymid - y0)*(ymid - y0)))
zfaces = np.exp(-0.01 * ((xmid - x0) * (xmid - x0) +
(ymid - y0) * (ymid - y0)))

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