plot: github.com/sksullivan/plot/plotutil Index | Examples | Files

package plotutil

import "github.com/sksullivan/plot/plotutil"

Package plotutil contains a small number of utilites for creating plots.

This package is under active development so portions of it may change.

Index

Examples

Package Files

add.go errorpoints.go plotutil.go

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),
}

func AddBoxPlots Uses

func AddBoxPlots(plt *plot.Plot, width vg.Length, vs ...interface{}) error

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 Uses

func AddErrorBars(plt *plot.Plot, vs ...interface{}) error

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 Uses

func AddLinePoints(plt *plot.Plot, vs ...interface{}) error

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 Uses

func AddLines(plt *plot.Plot, vs ...interface{}) error

AddLines adds Line 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 dashes shape via the Color and Dashes 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 AddScatters Uses

func AddScatters(plt *plot.Plot, vs ...interface{}) error

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 Uses

func AddStackedAreaPlots(plt *plot.Plot, xs plotter.Valuer, vs ...interface{}) error

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 Uses

func AddXErrorBars(plt *plot.Plot, es ...interface {
    plotter.XYer
    plotter.XErrorer
}) error

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 Uses

func AddYErrorBars(plt *plot.Plot, es ...interface {
    plotter.XYer
    plotter.YErrorer
}) error

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 Uses

func Color(i int) color.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 Uses

func Dashes(i int) []vg.Length

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 Uses

func MeanAndConf95(vls []float64) (mean, lowerr, higherr float64)

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 Uses

func MedianAndMinMax(vls []float64) (med, lowerr, higherr float64)

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 Uses

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.

type ErrorPoints Uses

type ErrorPoints struct {
    plotter.XYs
    plotter.XErrors
    plotter.YErrors
}

ErrorPoints holds a set of x, y pairs along with their X and Y errors.

Code:

// 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 + (rand.Float64() - 0.5)
        xys[j].Y = center + (rand.Float64() - 0.5)
    }
}

plt, err := plot.New()
if err != nil {
    panic(err)
}

mean95, err := NewErrorPoints(MeanAndConf95, pts...)
if err != nil {
    panic(err)
}
medMinMax, err := NewErrorPoints(MedianAndMinMax, pts...)
if err != nil {
    panic(err)
}
err = AddLinePoints(plt,
    "mean and 95% confidence", mean95,
    "median and minimum and maximum", medMinMax)
if err != nil {
    panic(err)
}
if err := AddErrorBars(plt, mean95, medMinMax); err != nil {
    panic(err)
}
if err := AddScatters(plt, pts[0], pts[1], pts[2], pts[3], pts[4]); err != nil {
    panic(err)
}

plt.Save(4, 4, "centroids.png")

func NewErrorPoints Uses

func NewErrorPoints(f func([]float64) (c, l, h float64), pts ...plotter.XYer) (*ErrorPoints, error)

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.

Package plotutil imports 9 packages (graph). Updated 2016-08-04. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).