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 21eb2ed

Browse filesBrowse files
authored
Merge pull request #7682 from efiring/image_masked_example
DOC: remove overlapping text from image_masked.py
2 parents 4c2a412 + 683f3df commit 21eb2ed
Copy full SHA for 21eb2ed

File tree

Expand file treeCollapse file tree

1 file changed

+27
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-16
lines changed

‎examples/pylab_examples/image_masked.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/image_masked.py
+27-16Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
get a filled contour effect.
66
"""
77
from copy import copy
8-
from numpy import ma
9-
import matplotlib.colors as colors
8+
9+
import numpy as np
1010
import matplotlib.pyplot as plt
11+
import matplotlib.colors as colors
1112
import matplotlib.mlab as mlab
12-
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)
@@ -31,31 +33,40 @@
3133
# If you comment out all the palette.set* lines, you will see
3234
# all the defaults; under and over will be colored with the
3335
# first and last colors in the palette, respectively.
34-
Zm = ma.masked_where(Z > 1.2, Z)
36+
Zm = np.ma.masked_where(Z > 1.2, Z)
3537

3638
# By setting vmin and vmax in the norm, we establish the
3739
# range to which the regular palette color scale is applied.
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(nrows=2, 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.