File: t_Contour_std.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (50 lines) | stat: -rwxr-xr-x 1,250 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
45
46
47
48
49
50
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()

# Create a function
inputVar = ot.Description(2)
inputVar[0] = "x"
inputVar[1] = "y"
formula = ot.Description(1)
formula[0] = "exp(-sin(cos(y)^2*x^2+sin(x)^2*y^2))"
f = ot.SymbolicFunction(inputVar, formula)

# Generate the data for the curves to be drawn
discretization = ot.Point(2)
nX = 75
nY = 75
discretization[0] = nX
discretization[1] = nY
inputData = ot.Box(discretization).generate()
inputData *= [10.0] * 2
inputData += [-5.0] * 2
data = f(inputData)
size = 7
levels = ot.Point(size)
for i in range(size):
    levels[i] = (0.5 + i) / size
# Create an empty graph
myGraph = ot.Graph("Complex iso lines", "u1", "u2", True, "topright")

# Create the first cloud
myContour = ot.Contour(nX + 2, nY + 2, data)
myContour.setLevels(levels)
myContour.setColor("red")
print("contour=", myContour)

# Modify it to filled Contour
myContour.setColorMap("inferno")
myContour.setAlpha(0.5)
myContour.setExtend("min")
myContour.setColorBarPosition("left")
myContour.setColorMapNorm("symlog")
myContour.setVmin(3)
myContour.setHatches(ot.Description(["/", "\\", "+/", "*"]))
myContour.setIsFilled(True)
print("filled contour=", myContour.__repr__())

# Then, draw it
myGraph.add(myContour)