File: example8.py

package info (click to toggle)
python-biggles 1.6.4-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 628 kB
  • ctags: 789
  • sloc: python: 3,728; ansic: 1,103; makefile: 85; pascal: 42
file content (68 lines) | stat: -rwxr-xr-x 1,626 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python

import sys
sys.path.insert(1,'..')

import biggles
import Numeric

#
# Create example 2-dimensional data set of two solitons colliding.
#
n = 64
x = Numeric.arange( -10., 10., 20./n )
t = Numeric.arange( -1., 1., 2./n )
z = Numeric.zeros( (len(x),len(t)), Numeric.Float )

for i in range(len(x)):
	for j in range(len(t)):
		z[i,j] = -12. * (3. + 4.*Numeric.cosh(2.*x[i]-8.*t[j]) \
			+ Numeric.cosh(4.*x[i] - 64.*t[j])) / \
			(3.*Numeric.cosh(x[i]-28.*t[j]) \
			+ Numeric.cosh(3.*x[i]-36.*t[j]))**2

#
# Make contour component.
#
c = biggles.Contours( z, x, t, color="red" )

#
# For fine-grained color control, the Contours component allows you to
# specify a function which returns the color applied to each contour line.
# The arguments passed to the function are:
#
#	i	integer index of contour (0,..,n-1)
#	n 	total number of contours
#	z0	z value of contour
#	z_min	minimum z contour value
#	z_max	maximum z contour value
#
# The function should return a valid color, or None for the default.
#
# Here we show how to set every other contour to blue. The remaining 
# contours are drawn with the default color, defined above to be red.
#
def even_blue( i, n, z0, z_min, z_max ):
	if i % 2 == 0:
		return 0x0000ff
	return None

c.func_color = even_blue

#
# Similarly, Contours accepts similar functions for line type (.func_linestyle)
# and width (.func_linewidth). The arguments passed are the same.
#

#
# Make framed plot container and add contour component.
#
p = biggles.FramedPlot()
p.add( c )

#
# Output.
#
#p.write_img( 400, 400, "example8.png" )
#p.write_eps( "example8.eps" )
p.show()