5 # A Histogram displays a histogram of numeric data.
7 class HistogramAppearance(LabelAppearance
, Define
):
9 def define(self
, parent
):
10 Define
.define(self
, (parent
, ''))
15 def setdata(self
, ydata
, scale
):
17 self
.scale
= scale
# (min, max)
18 self
.parent
.change(self
.bounds
)
20 def drawpict(self
, d
):
21 (left
, top
), (right
, bottom
) = self
.bounds
24 width
, height
= right
-left
, bottom
-top
27 v1
= top
+ height
# constant
28 h1
= left
# changed in loop
29 for i
in range(npoints
):
31 v0
= top
+ height
- (ydata
[i
]-min)*height
/size
32 h1
= left
+ (i
+1) * width
/npoints
33 d
.paint((h0
, v0
), (h1
, v1
))
36 class Histogram(NoReactivity
, HistogramAppearance
): pass