File: plotcontour.test

package info (click to toggle)
tklib 0.5-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,136 kB
  • ctags: 1,658
  • sloc: tcl: 36,353; sh: 3,045; ansic: 792; makefile: 105; exp: 21; sed: 16
file content (222 lines) | stat: -rwxr-xr-x 5,016 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Informal test for plotcontour
#
source [file join [file dirname [info script]] plotchart.tcl]
package require Plotchart

test "Plotcontours-1.0" "Informal test for plotcontour" {
########################################################################

proc cowboyhat {x y} {
   set x1 [expr {$x/9.0}]
   set y1 [expr {$y/9.0}]

   expr { 3.0 * (1.0-($x1*$x1+$y1*$y1))*(1.0-($x1*$x1+$y1*$y1)) }
}


#
# Main code
#
set choice 1

if {$choice == 0} {

set x { {0.0 1.0 2.0 3.0}
        {0.0 1.0 2.0 3.0}
        {0.0 1.0 2.0 3.0}
        {0.0 1.0 2.0 3.0} }

set y { {0.0 0.0 0.0 0.0}
        {1.0 1.0 1.0 1.0}
        {2.0 2.0 2.0 2.0}
        {3.0 3.0 3.0 3.0} }


set f { {0.0 0.0 2.0 3.0}
        {0.0 0.0 2.0 3.0}
        {2.0 2.0 3.0 4.0}
        {3.0 3.0 4.0 5.0} }

set contours [list 1.0 2.0 3.0 4.0 5.0 ]

# set contours [list 1.0 1.3 1.6 2.0 2.3 2.6 3.0 3.3 3.6 4.0 4.3 4.6 5.0 5.3 ]

set xlimits {0 3.5 0.5}
set ylimits {0 3.5 0.5}

}


if {$choice == 1} {

set x { {0.0 100.0 200.0}
        {0.0 100.0 200.0}
        {0.0 100.0 200.0}
        {0.0 100.0 200.0}}
set y { {0.0   0.0   0.0}
       {30.0  30.0  30.0}
       {60.0  60.0  60.0}
       {90.0  90.0  90.0}}
set f { {0.0   1.0  10.0}
       { 0.0  30.0  30.0}
       {10.0  60.0  60.0}
       {30.0  90.0  90.0}}

set contours [list \
     0.0             \
     5.2631578947    \
     10.5263157895   \
     15.7894736842   \
     21.0526315789   \
     26.3157894737   \
     31.5789473684   \
     36.8421052632   \
     42.1052631579   \
     47.3684210526   \
     52.6315789474   \
     57.8947368421   \
     63.1578947368   \
     68.4210526316   \
     73.6842105263   \
     78.9473684211   \
     84.2105263158   \
     89.4736842105   \
     94.7368421053   \
     100.0           \
     105.263157895   \
              ]

 set xlimits {0 200 50}
 set ylimits {0 100 20}

}

########################################################################

wm title . "Contour Demo : shade (jet colormap)"

set c [canvas .c  -background white \
          -width 500 -height 500]

pack   $c  -fill both -side top

set chart [::Plotchart::createXYPlot $c $xlimits $ylimits]

::Plotchart::colorMap jet

#$chart contourlines $x $y $f $contours
$chart contourfill $x $y $f $contours
#$chart contourbox $x $y $f $contours
$chart grid $x $y

set t [toplevel .contourlines]
lappend windows $t
wm title $t "Contour Demo : contourlines (default colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart1 [::Plotchart::createXYPlot $c $xlimits $ylimits]
$chart1 grid $x $y
$chart1 contourlines $x $y $f $contours


set t [toplevel .hot]
lappend windows $t
wm title $t "Contour Demo : contourlines (hot colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart2 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap hot
$chart2 contourfill $x $y $f $contours
$chart2 grid $x $y


set t [toplevel .gray]
lappend windows $t
wm title $t "Contour Demo : gray contourfill , jet contourlines"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart3 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap gray
$chart3 contourfill $x $y $f $contours

::Plotchart::colorMap jet
$chart3 contourlines $x $y $f $contours
$chart3 grid $x $y


set t [toplevel .cool]
lappend windows $t
wm title $t "Contour Demo : contourlines (cool colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart4 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap cool
$chart4 contourfill $x $y $f $contours
$chart4 grid $x $y



set t [toplevel .defcont]
lappend windows $t
wm title $t "Contour Demo : default contours (jet colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart5 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap jet
$chart5 contourfill $x $y $f
$chart5 grid $x $y



set t [toplevel .3dcontour]
lappend windows $t
wm title $t "Contour Demo : contours on a 3DPlot"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set xlimits {-10. 10.  10.  }
set ylimits {-10. 10.  10.  }
set zlimits { -5. 10.   5.  }

set zmin   0.0
set zmax   3.0

set nc    51
set dz    [expr {($zmax - $zmin) / ($nc - 1)}]

set contours {}
for {set cnt 1} {$cnt < $nc} {incr cnt} {
    set zval [expr {$zmin + ($dz * ($cnt - 1))}]
    lappend contours $zval
}

set chart6 [::Plotchart::create3DPlot $c $xlimits $ylimits $zlimits]
::Plotchart::colorMap jet
$chart6 title "3D Plot"
$chart6 plotfuncont cowboyhat $contours

after 10000 {
   foreach t $windows {
      destroy $t
   }
   set vv 1
}
vwait vv
set v 1
} 1


# -------------------------------------------------------------------------
::tcltest::cleanupTests