Menu

[r1418]: / trunk / htdocs / examples / contourf_demo.py  Maximize  Restore  History

Download this file

45 lines (36 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
from pylab import *
import matplotlib.numerix.ma as ma
origin = 'lower'
#origin = 'upper'
test_masking = False # There is a bug in filled contour masking.
if test_masking:
# Use a coarse grid so only a few masked points are needed.
delta = 0.5
else:
delta = 0.025
x = y = arange(-3.0, 3.01, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z1 - Z2
# interior badmask doesn't work yet for filled contours
if test_masking:
badmask = zeros(shape(Z))
badmask[5,5] = 1
badmask[5,6] = 1
Z[5,5] = 0
Z[5,6] = 0
badmask[0,0] = 1
Z[0,0] = 0
Z = ma.array(Z, mask=badmask)
levels, colls = contourf(X, Y, Z, 10, # [-1, -0.1, 0, 0.1],
#alpha=0.5,
cmap=cm.bone,
origin=origin)
levs2, colls2 = contour(X, Y, Z, levels,
colors = 'r',
origin=origin,
hold='on')
savefig('contourf_demo')
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.