-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathpie_charts.py
More file actions
63 lines (50 loc) · 2.01 KB
/
pie_charts.py
File metadata and controls
63 lines (50 loc) · 2.01 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import numpy as np
import tecplot as tp
from tecplot.constant import *
def normalize_variable(dataset, varname, nsigma=2):
'''
Normalize a variable such that the specified number of standard deviations
are within the range [0.5, 1] and the mean is transformed to 0.5. The
new variable will append " normalized" to the original variable's name.
'''
with tp.session.suspend():
newvarname = varname + ' normalized'
dataset.add_variable(newvarname)
data = np.concatenate([z.values(varname).as_numpy_array()
for z in dataset.zones()])
vmin = data.mean() - nsigma * data.std()
vmax = data.mean() + nsigma * data.std()
for z in dataset.zones():
arr = z.values(varname).as_numpy_array()
z.values(newvarname)[:] = (arr - vmin) / (vmax - vmin)
examples_dir = tp.session.tecplot_examples_directory()
infile = os.path.join(examples_dir, 'SimpleData', 'HeatExchanger.plt')
dataset = tp.data.load_tecplot(infile)
frame = tp.active_frame()
plot = frame.plot(PlotType.Cartesian2D)
plot.show_scatter = True
plot.axes.x_axis.min = 6
plot.axes.x_axis.max = 8
plot.axes.y_axis.min = 1.5
plot.axes.y_axis.max = 3.0
# Normalize variables to the range [0, 1]
normalize_variable(dataset, 'T(K)')
normalize_variable(dataset, 'P(N)')
frame.add_text(r'Normalized Temperature in Red', (50, 95), color=Color.Red)
frame.add_text(r'Normalized Pressure in Blue', (50, 92), color=Color.Blue)
#{DOC:highlight}[
fmaps = plot.fieldmaps()
fmaps.scatter.symbol().shape = GeomShape.PieChart
fmaps.scatter.size = 4.0
pie_charts = plot.scatter.pie_charts
pie_charts.wedge(0).show = True
pie_charts.wedge(0).show_label = False
pie_charts.wedge(0).variable = dataset.variable('T(K) normalized')
pie_charts.wedge(0).color = Color.Red
pie_charts.wedge(1).show = True
pie_charts.wedge(1).show_label = False
pie_charts.wedge(1).variable = dataset.variable('P(N) normalized')
pie_charts.wedge(1).color = Color.Blue
#]
tp.export.save_png('pie_charts.png')