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
|
#!/usr/bin/env tclsh
## -*- tcl -*-
package require Tcl 8.4
package require Tk
package require Plotchart
# plotdemos6.tcl --
# Test/demo program 6 for the Plotchart package
#
#
# Main code
# Note:
# The extremes and the canvas sizes are chosen so that the
# coordinate mapping is isometric!
#
#
canvas .c -background white -width 400 -height 400
canvas .c2 -background white -width 400 -height 200
pack .c .c2 -fill both -side top
set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
$s vectorconfig series1 -colour "red" -scale 40
$s vectorconfig series2 -colour "blue" -scale 50 -type nautical -centred 1
#
# Cartesian
#
set data {1.0 0.0 0.0 1.0 0.5 0.5 -2.0 1.0}
set x 30.0
set y 20.0
foreach {u v} $data {
$s vector series1 $x $y $u $v
}
#
# Nautical
#
set data {1.0 0.0 1.0 45.0 2.0 90.0}
set x 60.0
set y 40.0
foreach {length angle} $data {
$s vector series2 $x $y $length $angle
}
set s2 [::Plotchart::createXYPlot .c2 {0.0 100.0 10.0} {0.0 100.0 20.0}]
$s2 dotconfig series1 -colour "red" -scalebyvalue 1 -scale 2.5
$s2 dotconfig series2 -colour "magenta" -classes {0 blue 1 green 2 yellow 3 red} \
-scalebyvalue 0 -outline 0
$s2 dotconfig series3 -colour "magenta" -classes {0 blue 1 green 2 yellow 3 red} \
-scalebyvalue 1 -scale 2.5
set y1 20
set y2 50
set y3 80
set x 10
foreach value {-1.0 0.5 1.5 2.5 3.5 4.5} {
$s2 dot series1 $x $y1 $value
$s2 dot series2 $x $y2 $value
$s2 dot series3 $x $y3 $value
set x [expr {$x + 10}]
}
#
# A more interesting vector plot: the forces in a dipole field
#
proc forcesDipole {x y} {
set xd1 51.0
set yd1 50.0
set xd2 49.0
set yd2 50.0
set r1p3 [expr {pow(hypot($x-$xd1,$y-$yd1),3.0)}]
set r2p3 [expr {pow(hypot($x-$xd2,$y-$yd2),3.0)}]
set fx [expr {($x-$xd1)/$r1p3 - ($x-$xd2)/$r2p3}]
set fy [expr {($y-$yd1)/$r1p3 - ($y-$yd2)/$r2p3}]
return [list $fx $fy]
}
toplevel .dipole
canvas .dipole.c -background white -width 500 -height 500
pack .dipole.c -fill both -side top
set s [::Plotchart::createXYPlot .dipole.c {45.0 55.0 1.0} {45.0 55.0 1.0}]
$s title "Forces in a dipole field"
$s vectorconfig series1 -colour "black" -scale 40 -type polar
$s dotconfig dipole -colour red -scalebyvalue 0 -radius 5
$s dot dipole 49.0 50.0 1.0
$s dot dipole 51.0 50.0 1.0
for {set y 45.25} {$y < 55.0} {set y [expr {$y+0.5}]} {
for {set x 45.25} {$x < 55.0} {set x [expr {$x+0.5}]} {
foreach {u v} [forcesDipole $x $y] {break}
# Scale the vector for better display
set angle [expr {180.0*atan2($v,$u)/3.1415926}]
set length [expr {(0.5+hypot($u,$v))/(1.0+hypot($u,$v))}]
$s vector series1 $x $y $length $angle
}
}
#
# Simple demonstration of an R-chart
#
toplevel .rchart
canvas .rchart.c -background white -width 400 -height 200
pack .rchart.c -fill both -side top
set s [::Plotchart::createXYPlot .rchart.c {0.0 100.0 10.0} {0.0 50.0 10.0}]
$s title "R-chart (arbitrary data)"
$s dataconfig series1 -colour "green"
for {set x 1.0} {$x < 50.0} {set x [expr {$x+3.0}]} {
set y [expr {20.0 + 3.0*rand()}]
$s rchart series1 $x $y
}
#
# Now some data outside the expected range
#
$s rchart series1 50.0 41.0
$s rchart series1 52.0 42.0
$s rchart series1 54.0 39.0
#
# And continue with the well-behaved series
#
for {set x 57.0} {$x < 100.0} {set x [expr {$x+3.0}]} {
set y [expr {20.0 + 3.0*rand()}]
$s rchart series1 $x $y
}
|