Beispiel #1
0
func (b *BoxPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	x := trX(b.Location)
	if !da.ContainsX(x) {
		return
	}

	med := trY(b.Median)
	q1 := trY(b.Quartile1)
	q3 := trY(b.Quartile3)
	aLow := trY(b.AdjLow)
	aHigh := trY(b.AdjHigh)

	box := da.ClipLinesY([]plot.Point{
		{x - b.Width/2, q1},
		{x - b.Width/2, q3},
		{x + b.Width/2, q3},
		{x + b.Width/2, q1},
		{x - b.Width/2 - b.BoxStyle.Width/2, q1},
	})
	da.StrokeLines(b.BoxStyle, box...)

	medLine := da.ClipLinesY([]plot.Point{
		{x - b.Width/2, med},
		{x + b.Width/2, med},
	})
	da.StrokeLines(b.MedianStyle, medLine...)

	cap := b.CapWidth / 2
	whisks := da.ClipLinesY([]plot.Point{{x, q3}, {x, aHigh}},
		[]plot.Point{{x - cap, aHigh}, {x + cap, aHigh}},
		[]plot.Point{{x, q1}, {x, aLow}},
		[]plot.Point{{x - cap, aLow}, {x + cap, aLow}})
	da.StrokeLines(b.WhiskerStyle, whisks...)

	for _, out := range b.Outside {
		y := trY(b.Value(out))
		da.DrawGlyph(b.GlyphStyle, plot.Point{x, y})
	}
}
Beispiel #2
0
func (b HorizBoxPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	y := trY(b.Location)
	if !da.ContainsY(y) {
		return
	}

	med := trX(b.Median)
	q1 := trX(b.Quartile1)
	q3 := trX(b.Quartile3)
	aLow := trX(b.AdjLow)
	aHigh := trX(b.AdjHigh)

	box := da.ClipLinesX([]plot.Point{
		{q1, y - b.Width/2},
		{q3, y - b.Width/2},
		{q3, y + b.Width/2},
		{q1, y + b.Width/2},
		{q1, y - b.Width/2 - b.BoxStyle.Width/2},
	})
	da.StrokeLines(b.BoxStyle, box...)

	medLine := da.ClipLinesX([]plot.Point{
		{med, y - b.Width/2},
		{med, y + b.Width/2},
	})
	da.StrokeLines(b.MedianStyle, medLine...)

	cap := b.CapWidth / 2
	whisks := da.ClipLinesX([]plot.Point{{q3, y}, {aHigh, y}},
		[]plot.Point{{aHigh, y - cap}, {aHigh, y + cap}},
		[]plot.Point{{q1, y}, {aLow, y}},
		[]plot.Point{{aLow, y - cap}, {aLow, y + cap}})
	da.StrokeLines(b.WhiskerStyle, whisks...)

	for _, out := range b.Outside {
		x := trX(b.Value(out))
		da.DrawGlyph(b.GlyphStyle, plot.Point{x, y})
	}
}
Beispiel #3
0
func (b *QuartPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	x := trX(b.Location)
	if !da.ContainsX(x) {
		return
	}

	med := plot.Pt(x, trY(b.Median))
	q1 := trY(b.Quartile1)
	q3 := trY(b.Quartile3)
	aLow := trY(b.AdjLow)
	aHigh := trY(b.AdjHigh)

	da.StrokeLine2(b.WhiskerStyle, x, aHigh, x, q3)
	da.DrawGlyph(b.MedianStyle, med)
	da.StrokeLine2(b.WhiskerStyle, x, aLow, x, q1)

	ostyle := b.MedianStyle
	ostyle.Radius = b.MedianStyle.Radius / 2
	for _, out := range b.Outside {
		y := trY(b.Value(out))
		da.DrawGlyph(ostyle, plot.Pt(x, y))
	}
}
Beispiel #4
0
// Thumbnail the thumbnail for the Scatter,
// implementing the plot.Thumbnailer interface.
func (pts *Scatter) Thumbnail(da *plot.DrawArea) {
	da.DrawGlyph(pts.GlyphStyle, da.Center())
}
Beispiel #5
0
// Plot draws the Scatter, implementing the plot.Plotter
// interface.
func (pts *Scatter) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	for _, p := range pts.XYs {
		da.DrawGlyph(pts.GlyphStyle, plot.Pt(trX(p.X), trY(p.Y)))
	}
}