Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7c9fd69

Browse filesBrowse files
committed
Example: remove overlapping text from image_masked.py
This also makes several other changes that clarify the example and improve the code.
1 parent db9b188 commit 7c9fd69
Copy full SHA for 7c9fd69

File tree

Expand file treeCollapse file tree

1 file changed

+23
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-12
lines changed

‎examples/pylab_examples/image_masked.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/image_masked.py
+23-12Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import numpy as np
1313

1414
# compute some interesting data
15-
delta = 0.025
16-
x = y = np.arange(-3.0, 3.0, delta)
15+
x0, x1 = -5, 5
16+
y0, y1 = -3, 3
17+
x = np.linspace(x0, x1, 500)
18+
y = np.linspace(y0, y1, 500)
1719
X, Y = np.meshgrid(x, y)
1820
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
1921
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
@@ -38,24 +40,33 @@
3840
# Anything above that range is colored based on palette.set_over, etc.
3941

4042
# set up the axes
41-
fig, (ax1, ax2) = plt.subplots(1, 2)
43+
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 5.4))
4244

4345
# plot using 'continuous' color map
4446
im = ax1.imshow(Zm, interpolation='bilinear',
4547
cmap=palette,
46-
norm=colors.Normalize(vmin=-1.0, vmax=1.0, clip=False),
47-
origin='lower', extent=[-3, 3, -3, 3])
48-
ax1.set_title('Green=low, Red=high, Blue=bad')
49-
fig.colorbar(im, extend='both', orientation='horizontal', shrink=0.8, ax=ax1)
48+
norm=colors.Normalize(vmin=-1.0, vmax=1.0),
49+
aspect='auto',
50+
origin='lower',
51+
extent=[x0, x1, y0, y1])
52+
ax1.set_title('Green=low, Red=high, Blue=masked')
53+
cbar = fig.colorbar(im, extend='both', shrink=0.9, ax=ax1)
54+
cbar.set_label('uniform')
55+
for ticklabel in ax1.xaxis.get_ticklabels():
56+
ticklabel.set_visible(False)
5057

51-
# plot using 'discrete' color map
58+
# Plot using a small number of colors, with unevenly spaced boundaries.
5259
im = ax2.imshow(Zm, interpolation='nearest',
5360
cmap=palette,
5461
norm=colors.BoundaryNorm([-1, -0.5, -0.2, 0, 0.2, 0.5, 1],
55-
ncolors=256, clip=False),
56-
origin='lower', extent=[-3, 3, -3, 3])
62+
ncolors=palette.N),
63+
aspect='auto',
64+
origin='lower',
65+
extent=[x0, x1, y0, y1])
5766
ax2.set_title('With BoundaryNorm')
58-
fig.colorbar(im, extend='both', spacing='proportional',
59-
orientation='horizontal', shrink=0.8, ax=ax2)
67+
cbar = fig.colorbar(im, extend='both', spacing='proportional',
68+
shrink=0.9, ax=ax2)
69+
cbar.set_label('proportional')
6070

71+
fig.suptitle('imshow, with out-of-range and masked data')
6172
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.