plotutil

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: BSD-3-Clause Imports: 9 Imported by: 483

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

Examples

Constants

This section is empty.

Variables

View Source
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),
}
View Source
var DefaultColors = SoftColors

DefaultColors is a set of colors used by the Color function.

View Source
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.

DefaultGlyphShapes is a set of GlyphDrawers used by the Shape function.

View Source
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Example
package main

import (
	"golang.org/x/exp/rand"

	"gonum.org/v1/plot"
	"gonum.org/v1/plot/plotter"
	"gonum.org/v1/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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL