File: contour_demo.py

package info (click to toggle)
scitools 0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 17,252 kB
  • ctags: 2,871
  • sloc: python: 28,744; sh: 112; makefile: 15
file content (44 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download | duplicates (2)
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 scitools.std import *

# A simple contour plot of the peaks function:
contour(peaks())

figure()
# Here we draw 15 red contour lines with double line width:
xv, yv = ndgrid(linspace(-3,3,31),linspace(-3,3,31))
values = xv*exp(-xv**2-yv**2)
contour(xv, yv, values, 15, 'r', linewidth=2)

figure()
# Draw contour lines with labels at -2, 0, 2, and 5:
values = peaks(xv, yv)
contour(xv, yv, values, [-2,0,2,5])

figure()
# Here we combine a contour plot with a quiver plot (currently not
# working with the Gnuplot backend):
x = y = linspace(-2,2,21)
xv, yv = ndgrid(x, y, sparse=False)
values = sin(xv)*sin(yv)*exp(-xv**2 - xv**2)
dx, dy = gradient(values)
contour(xv, yv, values, 10, show=False)
hold('on')
quiver(xv, yv, dx, dy, 2, show=True)
hold('off')

figure()
# Another example:
x = linspace(-2,2,201)
y = linspace(-1,1,31)
xv, yv = ndgrid(x,y)
values = sin(3*yv - xv**2 + 1) + cos(2*yv**2 - 2*xv)
contour(xv,yv,values,clabels='on')  # contour(x,y,values,..) also works

figure()
# The contourf command draws filled contours:
values = peaks(201)
contourf(values, 10, caxis=[-20, 20], title='Filled Contour Plot')

raw_input('Press Return key to quit: ')