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
|
#!/usr/bin/ruby
require 'tk'
require 'tkextlib/tcllib/plotchart'
###############################
c1 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
c2 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
c3 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
Tk.pack(c1,c2,c3, :fill=>:both, :side=>:top)
h = TkToplevel.new(:title=>'h')
hc1 = TkCanvas.new(h, :background=>'white', :width=>400, :height=>200)
hc2 = TkCanvas.new(h, :background=>'white', :width=>400, :height=>200)
Tk.pack(hc1,hc2, :fill=>:both, :side=>:top)
v = TkToplevel.new(:title=>'v')
vc1 = TkCanvas.new(v, :background=>'white', :width=>400, :height=>200)
vc2 = TkCanvas.new(v, :background=>'white', :width=>400, :height=>200)
vc3 = TkCanvas.new(v, :background=>'white', :width=>400, :height=>200)
Tk.pack(vc1,vc2,vc3, :fill=>:both, :side=>:top)
###############################
s = Tk::Tcllib::Plotchart::XYPlot.new(c1, [0.0, 100.0, 10.0],
[0.0, 100.0, 20.0])
xd = 5.0
yd = 20.0
xold = 0.0
yold = 50.0
s.dataconfig('series1', :color=>'red')
(0..19).each{|i|
xnew = xold + xd
ynew = yold + (rand() - 0.5) * yd
ynew2 = yold + (rand() - 0.5) * 2.0 * yd
s.plot('series1', xnew, ynew)
s.plot('series2', xnew, ynew2)
xold = xnew
yold = ynew
}
s.xtext "X-coordinate"
s.ytext "Y-data"
s.title "Aha!"
c1.wait_visibility
s.save_plot "aha.ps"
###############################
s = Tk::Tcllib::Plotchart::Piechart.new(c2)
s.plot([ ["Long names", 10], ["Short names", 30],
["Average", 40], ["Ultra-short names", 5] ])
#
# Note: title should be shifted up
# - distinguish a separate title area
#
s.title "Okay - this works"
###############################
s = Tk::Tcllib::Plotchart::PolarPlot.new(c3, [3.0, 1.0])
0.step(359, 10){|angle|
rad = 1.0+Math.cos(angle*Math::PI/180.0)
s.plot('cardioid', rad, angle)
}
s.title "Cardioid"
###############################
s = Tk::Tcllib::Plotchart::Barchart.new(hc1, %w(A B C D E),
[0.0, 10.0, 2.0], 2)
s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
s.title "Arbitrary data"
###############################
s = Tk::Tcllib::Plotchart::Barchart.new(hc2, %w(A B C D E),
[0.0, 20.0, 5.0], :stacked)
s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
s.title "Stacked diagram"
###############################
s = Tk::Tcllib::Plotchart::HorizontalBarchart.new(vc1, [0.0, 10.0, 2.0],
%w(A B C D E), 2)
s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
s.title "Arbitrary data"
###############################
s = Tk::Tcllib::Plotchart::HorizontalBarchart.new(vc2, [0.0, 20.0, 5.0],
%w(A B C D E), :stacked)
s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
s.title "Stacked diagram"
###############################
s = Tk::Tcllib::Plotchart::Timechart.new(vc3, "1 january 2004",
"31 december 2004", 4)
s.period("Spring", "1 march 2004", "1 june 2004", 'green')
s.period("Summer", "1 june 2004", "1 september 2004", 'yellow')
s.vertline("1 jan", "1 january 2004")
s.vertline("1 apr", "1 april 2004")
s.vertline("1 jul", "1 july 2004")
s.vertline("1 oct", "1 october 2004")
s.milestone("Longest day", "21 july 2004")
s.title "Seasons (northern hemisphere)"
###############################
z = TkToplevel.new(:title=>'3D')
zc1 = TkCanvas.new(z, :background=>'white', :width=>400, :height=>300)
zc2 = TkCanvas.new(z, :background=>'white', :width=>400, :height=>250)
Tk.pack(zc1,zc2)
s = Tk::Tcllib::Plotchart::Plot3D.new(zc1,
[0, 10, 3], [-10, 10, 10], [0, 10, 2.5])
s.title "3D Plot"
s.plot_function{|x, y|
# cowboyhat
x1 = x.to_f/9.0
y1 = y.to_f/9.0
3.0 * (1.0-(x1*x1+y1*y1))*(1.0-(x1*x1+y1*y1))
}
s = Tk::Tcllib::Plotchart::Plot3D.new(zc2,
[0, 10, 3], [-10, 10, 10], [0, 10, 2.5])
s.title "3D Plot - data "
s.colour("green", "black")
s.plot_data([ [1.0, 2.0, 1.0, 0.0],
[1.1, 3.0, 1.1, -0.5],
[3.0, 1.0, 4.0, 5.0] ])
###############################
Tk.mainloop
|