Documentation ¶
Overview ¶
Package plotutil contains a small number of utilites for creating plots.
This package is under active development so portions of it may change.
Index ¶
- Variables
- func AddBoxPlots(plt *plot.Plot, width vg.Length, vs ...interface{}) error
- func AddErrorBars(plt *plot.Plot, vs ...interface{}) error
- func AddLinePoints(plt *plot.Plot, vs ...interface{}) error
- func AddLines(plt *plot.Plot, vs ...interface{}) error
- func AddScatters(plt *plot.Plot, vs ...interface{}) error
- func AddStackedAreaPlots(plt *plot.Plot, xs plotter.Valuer, vs ...interface{}) error
- func AddXErrorBars(plt *plot.Plot, es ...) error
- func AddYErrorBars(plt *plot.Plot, es ...) error
- func Color(i int) color.Color
- func Dashes(i int) []vg.Length
- func MeanAndConf95(vls []float64) (mean, lowerr, higherr float64)
- func MedianAndMinMax(vls []float64) (med, lowerr, higherr float64)
- func Shape(i int) draw.GlyphDrawer
- type ErrorPoints
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DarkColors = []color.Color{
rgb(238, 46, 47),
rgb(0, 140, 72),
rgb(24, 90, 169),
rgb(244, 125, 35),
rgb(102, 44, 145),
rgb(162, 29, 33),
rgb(180, 56, 148),
}
var DefaultColors = SoftColors
DefaultColors is a set of colors used by the Color function.
var DefaultDashes = [][]vg.Length{ {}, {vg.Points(6), vg.Points(2)}, {vg.Points(2), vg.Points(2)}, {vg.Points(1), vg.Points(1)}, {vg.Points(5), vg.Points(2), vg.Points(1), vg.Points(2)}, {vg.Points(10), vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2)}, {vg.Points(10), vg.Points(2), vg.Points(2), vg.Points(2)}, {vg.Points(5), vg.Points(2), vg.Points(5), vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2)}, {vg.Points(4), vg.Points(2), vg.Points(4), vg.Points(1), vg.Points(1), vg.Points(1), vg.Points(1), vg.Points(1), vg.Points(1), vg.Points(1)}, }
DefaultDashes is a set of dash patterns used by the Dashes function.
var DefaultGlyphShapes = []draw.GlyphDrawer{ draw.RingGlyph{}, draw.SquareGlyph{}, draw.TriangleGlyph{}, draw.CrossGlyph{}, draw.PlusGlyph{}, draw.CircleGlyph{}, draw.BoxGlyph{}, draw.PyramidGlyph{}, }
DefaultGlyphShapes is a set of GlyphDrawers used by the Shape function.
var SoftColors = []color.Color{
rgb(241, 90, 96),
rgb(122, 195, 106),
rgb(90, 155, 212),
rgb(250, 167, 91),
rgb(158, 103, 171),
rgb(206, 112, 88),
rgb(215, 127, 180),
}
Functions ¶
func AddBoxPlots ¶
AddBoxPlots adds box plot plotters to a plot and sets the X axis of the plot to be nominal. The variadic arguments must be either strings or plotter.Valuers. Each valuer adds a box plot to the plot at the X location corresponding to the number of box plots added before it. If a plotter.Valuer is immediately preceeded by a string then the string value is used to label the tick mark for the box plot's X location.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddErrorBars ¶
AddErrorBars adds XErrorBars and YErrorBars to a plot. The variadic arguments must be of type plotter.XYer, and must be either a plotter.XErrorer, plotter.YErrorer, or both. Each errorer is added to the plot the color from the Colors function corresponding to its position in the argument list.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddLinePoints ¶
AddLinePoints adds Line and Scatter plotters to a plot. The variadic arguments must be either strings or plotter.XYers. Each plotter.XYer is added to the plot using the next color, dashes, and glyph shape via the Color, Dashes, and Shape functions. If a plotter.XYer is immediately preceeded by a string then a legend entry is added to the plot using the string as the name.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddLines ¶
AddLines adds Line plotters to a plot. The variadic arguments must be a string or one of a plotting type, plotter.XYers or *plotter.Function. Each plotting type is added to the plot using the next color and dashes shape via the Color and Dashes functions. If a plotting type is immediately preceeded by a string then a legend entry is added to the plot using the string as the name.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddScatters ¶
AddScatters adds Scatter plotters to a plot. The variadic arguments must be either strings or plotter.XYers. Each plotter.XYer is added to the plot using the next color, and glyph shape via the Color and Shape functions. If a plotter.XYer is immediately preceeded by a string then a legend entry is added to the plot using the string as the name.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddStackedAreaPlots ¶
AddStackedAreaPlots adds stacked area plot plotters to a plot. The variadic arguments must be either strings or plotter.Valuers. Each valuer adds a stacked area plot to the plot below the stacked area plots added before it. If a plotter.Valuer is immediately preceeded by a string then the string value is used to label the legend. Plots should be added in order of tallest to shortest, because they will be drawn in the order they are added (i.e. later plots will be painted over earlier plots).
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddXErrorBars ¶
AddXErrorBars adds XErrorBars to a plot. The variadic arguments must be of type plotter.XYer, and plotter.XErrorer. Each errorer is added to the plot the color from the Colors function corresponding to its position in the argument list.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func AddYErrorBars ¶
AddYErrorBars adds YErrorBars to a plot. The variadic arguments must be of type plotter.XYer, and plotter.YErrorer. Each errorer is added to the plot the color from the Colors function corresponding to its position in the argument list.
If an error occurs then none of the plotters are added to the plot, and the error is returned.
func Color ¶
Color returns the ith default color, wrapping if i is less than zero or greater than the max number of colors in the DefaultColors slice.
func Dashes ¶
Dashes returns the ith default dash pattern, wrapping if i is less than zero or greater than the max number of dash patters in the DefaultDashes slice.
func MeanAndConf95 ¶
MeanAndConf95 returns the mean and the magnitude of the 95% confidence interval on the mean as low and high error values.
MeanAndConf95 may be used as the f argument to NewErrorPoints.
func MedianAndMinMax ¶
MedianAndMinMax returns the median value and error on the median given by the minimum and maximum data values.
MedianAndMinMax may be used as the f argument to NewErrorPoints.
func Shape ¶
func Shape(i int) draw.GlyphDrawer
Shape returns the ith default glyph shape, wrapping if i is less than zero or greater than the max number of GlyphDrawers in the DefaultGlyphShapes slice.
Types ¶
type ErrorPoints ¶
ErrorPoints holds a set of x, y pairs along with their X and Y errors.
Example ¶
package main import ( "golang.org/x/exp/rand" "github.com/emptywe/plot" "github.com/emptywe/plot/plotter" "github.com/emptywe/plot/plotutil" ) func main() { rnd := rand.New(rand.NewSource(1)) // Get some random data. n, m := 5, 10 pts := make([]plotter.XYer, n) for i := range pts { xys := make(plotter.XYs, m) pts[i] = xys center := float64(i) for j := range xys { xys[j].X = center + (rnd.Float64() - 0.5) xys[j].Y = center + (rnd.Float64() - 0.5) } } plt := plot.New() mean95, err := plotutil.NewErrorPoints(plotutil.MeanAndConf95, pts...) if err != nil { panic(err) } medMinMax, err := plotutil.NewErrorPoints(plotutil.MedianAndMinMax, pts...) if err != nil { panic(err) } err = plotutil.AddLinePoints(plt, "mean and 95% confidence", mean95, "median and minimum and maximum", medMinMax) if err != nil { panic(err) } if err := plotutil.AddErrorBars(plt, mean95, medMinMax); err != nil { panic(err) } if err := plotutil.AddScatters(plt, pts[0], pts[1], pts[2], pts[3], pts[4]); err != nil { panic(err) } err = plt.Save(4, 4, "centroids.png") if err != nil { panic(err) } }
Output:
func NewErrorPoints ¶
NewErrorPoints returns a new ErrorPoints where each point in the ErrorPoints is given by evaluating the center function on the Xs and Ys for the corresponding set of XY values in the pts parameter. The XError and YError are computed likewise, using the err function.
This function can be useful for summarizing sets of scatter points using a single point and error bars for each element of the scatter.