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

Skip to content

Commit d6e7501

Browse files
committed
refactored contour code
svn path=/trunk/matplotlib/; revision=1060
1 parent 3172a48 commit d6e7501

7 files changed

Lines changed: 1067 additions & 904 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
New entries should be added at the top
22

3+
2005-03-09 Refactored contour functionality into dedicated module
4+
35
2005-03-09 Added Eric's contourf updates and Nadia's clabel functionality
46
- TODO, factor clabel into a dedicated class
57

MANIFEST

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ agg22/svg/win32_api/svg_test.dsp
248248
agg22/svg/win32_api/svg_test.dsw
249249
examples/README
250250
examples/__init__.py
251-
examples/_tmp_simple_plot.py
252251
examples/accented_text.py
253252
examples/agg_oo.py
254253
examples/alignment_test.py
@@ -298,6 +297,7 @@ examples/figimage_demo.py
298297
examples/figlegend_demo.py
299298
examples/figtext.py
300299
examples/fill_between.py
300+
examples/fill_between_posneg.py
301301
examples/fill_demo.py
302302
examples/fill_spiral.py
303303
examples/finance_demo.py
@@ -522,23 +522,25 @@ lib/matplotlib/artist.py
522522
lib/matplotlib/axes.py
523523
lib/matplotlib/axis.py
524524
lib/matplotlib/backend_bases.py
525+
lib/matplotlib/backend_bases.py.~1.42.~
525526
lib/matplotlib/cbook.py
526527
lib/matplotlib/cm.py
527528
lib/matplotlib/collections.py
529+
lib/matplotlib/collections.py.~1.15.~
528530
lib/matplotlib/colors.py
529531
lib/matplotlib/dates.py
530532
lib/matplotlib/figure.py
531533
lib/matplotlib/figure.py.~1.16.~
532534
lib/matplotlib/finance.py
533535
lib/matplotlib/font_manager.py
536+
lib/matplotlib/font_manager.py.~1.8.~
534537
lib/matplotlib/image.py
535538
lib/matplotlib/legend.py
536539
lib/matplotlib/lines.py
537540
lib/matplotlib/lines.py.~1.23.~
538541
lib/matplotlib/mathtext.py
539542
lib/matplotlib/mlab.py
540543
lib/matplotlib/patches.py
541-
lib/matplotlib/path.py
542544
lib/matplotlib/pylab.py
543545
lib/matplotlib/pylab.py.~1.45.~
544546
lib/matplotlib/pyparsing.py

examples/contour_image.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
'''
3+
contour_image.py [options]
4+
5+
Test combinations of contouring, filled contouring, and image plotting.
6+
'''
7+
from pylab import *
8+
import matplotlib.numerix
9+
print 'Using', matplotlib.numerix.which[0]
10+
11+
from optparse import OptionParser
12+
parser = OptionParser(usage=__doc__.rstrip())
13+
parser.add_option("-b", "--badmask", dest="badmask", default="none",
14+
help="'none', 'edge', 'interior'; default is 'none'")
15+
parser.add_option("-d", "--delta", dest="delta", type="float", default=0.5,
16+
help="grid increment in x and y; default is 0.5")
17+
parser.add_option("-s", "--save", dest="save", default=None, metavar="FILE",
18+
help="Save to FILE; default is to not save.")
19+
20+
#Default delta is large because that makes it fast, and it illustrates
21+
# the correct registration between image and contours.
22+
23+
import sys
24+
# We have to strip out the numerix arguments before passing the
25+
# input arguments to the parser.
26+
Args = [arg for arg in sys.argv if arg not in ('--Numeric', '--numarray')]
27+
options, args = parser.parse_args(Args)
28+
delta = options.delta
29+
badmask = options.badmask
30+
31+
x = y = arange(-3.0, 3.01, delta)
32+
X, Y = meshgrid(x, y)
33+
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
34+
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
35+
Z = (Z1 - Z2) * 10
36+
Zbm = Z.copy()
37+
38+
ny, nx = shape(Z)
39+
40+
Badmask = zeros(shape(Z))
41+
if badmask == 'none':
42+
Badmask = None
43+
elif badmask == 'edge':
44+
Badmask[:ny/5,:] = 1
45+
Zbm[:ny/5,:] = 100 # test ability to ignore bad values
46+
elif badmask == 'interior':
47+
Badmask[ny/4:ny/2, nx/4:nx/2] = 1
48+
Zbm[ny/4:ny/2, nx/4:nx/2] = 100
49+
print "Interior masking works correctly for line contours only..."
50+
else:
51+
raise ValueError("badmask must be 'none', 'edge', or 'interior'")
52+
53+
figure(1)
54+
subplot(2,2,1)
55+
levels, colls = contourf(X, Y, Zbm, 10, # [-1, -0.1, 0, 0.1],
56+
cmap=cm.jet,
57+
badmask = Badmask
58+
)
59+
# Use levels output from previous call to guarantee they are the same.
60+
levs2, colls2 = contour(X, Y, Zbm, levels,
61+
colors = 'r',
62+
badmask = Badmask,
63+
hold='on')
64+
65+
levs3, colls3 = contour(X, Y, Zbm, (0,),
66+
colors = 'g',
67+
linewidths = 2,
68+
hold='on')
69+
title('Filled contours')
70+
#colorbar()
71+
# Major reworking of the colorbar mechanism is needed for filled contours!
72+
73+
subplot(2,2,2)
74+
imshow(Z)
75+
v = axis()
76+
contour(Z, levels, hold='on', colors = 'r', origin='upper')
77+
axis(v)
78+
title("Image, origin 'upper'")
79+
80+
subplot(2,2,3)
81+
imshow(Z, origin='lower')
82+
v = axis()
83+
contour(Z, levels, hold='on', colors = 'r', origin='lower')
84+
axis(v)
85+
title("Image, origin 'lower'")
86+
87+
subplot(2,2,4)
88+
imshow(Z, interpolation='nearest')
89+
v = axis()
90+
contour(Z, levels, hold='on', colors = 'r', origin='image')
91+
axis(v)
92+
ylim = get(gca(), 'ylim')
93+
set(gca(), ylim=ylim[::-1])
94+
title("Image, origin from rc, reversed y-axis")
95+
96+
if options.save is not None:
97+
savefig(options.save)
98+
99+
show()
100+

examples/contourf_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
1212
Z = Z1 - Z2
1313

14+
# interior badmask doesn't work yet for filled contours
1415
if 0:
1516
badmask = zeros(shape(Z))
1617

@@ -25,7 +26,7 @@
2526
levels, colls = contourf(X, Y, Z, 10, # [-1, -0.1, 0, 0.1],
2627
# badmask=badmask,
2728
#alpha=0.5,
28-
cmap=bone(),
29+
cmap=cm.bone,
2930
origin=origin)
3031

3132
levs2, colls2 = contour(X, Y, Z, levels,

0 commit comments

Comments
 (0)