plots

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package plots defines a variety of standard Plotters for the plot package.

Plotters use the primitives provided by the plot package to draw to the data area of a plot. This package provides some standard data styles such as lines, scatter plots, box plots, labels, and more.

Unlike the gonum/plot package, NaN values are treated as missing data points, and are just skipped over.

New* functions return an error if the data contains Inf or is empty. Some of the New* functions return other plotter-specific errors too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTableLinePoints

func AddTableLinePoints(plt *plot.Plot, tab Table, xcolumn, ycolumn int) (*Line, *Scatter, error)

AddTableLinePoints adds Line w/ Points with given x, y columns from given tabular data

func DrawBox

func DrawBox(pc *paint.Context, pos math32.Vector2, size float32)

func DrawCircle

func DrawCircle(pc *paint.Context, pos math32.Vector2, size float32)

func DrawCross

func DrawCross(pc *paint.Context, pos math32.Vector2, size float32)

func DrawPlus

func DrawPlus(pc *paint.Context, pos math32.Vector2, size float32)

func DrawPyramid

func DrawPyramid(pc *paint.Context, pos math32.Vector2, size float32)

func DrawRing

func DrawRing(pc *paint.Context, pos math32.Vector2, size float32)

func DrawShape

func DrawShape(pc *paint.Context, pos math32.Vector2, size float32, shape Shapes)

DrawShape draws the given shape

func DrawSquare

func DrawSquare(pc *paint.Context, pos math32.Vector2, size float32)

func DrawTriangle

func DrawTriangle(pc *paint.Context, pos math32.Vector2, size float32)

func NewLinePoints

func NewLinePoints(xys plot.XYer) (*Line, *Scatter, error)

NewLinePoints returns both a Line and a Scatter plot for the given point data.

func TableColumnIndex

func TableColumnIndex(tab Table, name string) int

Types

type BarChart

type BarChart struct {
	// Values are the plotted values
	Values plot.Values

	// YErrors is a copy of the Y errors for each point.
	Errors plot.Values

	// XYs is the actual pixel plotting coordinates for each value.
	XYs plot.XYs

	// PXYs is the actual pixel plotting coordinates for each value.
	PXYs plot.XYs

	// Offset is offset added to each X axis value relative to the
	// Stride computed value (X = offset + index * Stride)
	// Defaults to 1.
	Offset float32

	// Stride is distance between bars. Defaults to 1.
	Stride float32

	// Width is the width of the bars, which should be less than
	// the Stride to prevent bar overlap.
	// Defaults to .8
	Width float32

	// Pad is additional space at start / end of data range, to keep bars from
	// overflowing ends.  This amount is subtracted from Offset
	// and added to (len(Values)-1)*Stride -- no other accommodation for bar
	// width is provided, so that should be built into this value as well.
	// Defaults to 1.
	Pad float32

	// Color is the fill color of the bars.
	Color color.Color

	// LineStyle is the style of the line connecting the points.
	// Use zero width to disable lines.
	LineStyle plot.LineStyle

	// Horizontal dictates whether the bars should be in the vertical
	// (default) or horizontal direction. If Horizontal is true, all
	// X locations and distances referred to here will actually be Y
	// locations and distances.
	Horizontal bool

	// stackedOn is the bar chart upon which this bar chart is stacked.
	StackedOn *BarChart
}

A BarChart presents ordinally-organized data with rectangular bars with lengths proportional to the data values, and an optional error bar ("handle") at the top of the bar using given error value (single value, like a standard deviation etc, not drawn below the bar).

Bars are plotted centered at integer multiples of Stride plus Start offset. Full data range also includes Pad value to extend range beyond edge bar centers. Bar Width is in data units, e.g., should be <= Stride. Defaults provide a unit-spaced plot.

func NewBarChart

func NewBarChart(vs, ers plot.Valuer) (*BarChart, error)

NewBarChart returns a new bar chart with a single bar for each value. The bars heights correspond to the values and their x locations correspond to the index of their value in the Valuer. Optional error-bar values can be provided.

func (*BarChart) BarHeight

func (b *BarChart) BarHeight(i int) float32

BarHeight returns the maximum y value of the ith bar, taking into account any bars upon which it is stacked.

func (*BarChart) DataRange

func (b *BarChart) DataRange() (xmin, xmax, ymin, ymax float32)

DataRange implements the plot.DataRanger interface.

func (*BarChart) Defaults

func (b *BarChart) Defaults()

func (*BarChart) Plot

func (b *BarChart) Plot(plt *plot.Plot)

Plot implements the plot.Plotter interface.

func (*BarChart) StackOn

func (b *BarChart) StackOn(on *BarChart)

StackOn stacks a bar chart on top of another, and sets the bar positioning params to that of the chart upon which it is being stacked.

func (*BarChart) Thumbnail

func (b *BarChart) Thumbnail(plt *plot.Plot)

Thumbnail fulfills the plot.Thumbnailer interface.

func (*BarChart) XYData

func (b *BarChart) XYData() (data plot.XYer, pixels plot.XYer)

type Errors

type Errors []struct{ Low, High float32 }

Errors is a slice of low and high error values.

type Labels

type Labels struct {
	// XYs is a copy of the points for labels
	plot.XYs

	// PXYs is the actual pixel plotting coordinates for each XY value.
	PXYs plot.XYs

	// Labels is the set of labels corresponding to each point.
	Labels []string

	// TextStyle is the style of the label text.
	// Each label can have a different text style, but
	// by default they share a common one (len = 1)
	TextStyle []plot.TextStyle

	// Offset is added directly to the final label location.
	Offset units.XY
}

Labels implements the Plotter interface, drawing a set of labels at specified points.

func NewLabels

func NewLabels(d XYLabeller) (*Labels, error)

NewLabels returns a new Labels using defaults

func (*Labels) DataRange

func (l *Labels) DataRange() (xmin, xmax, ymin, ymax float32)

DataRange returns the minimum and maximum X and Y values

func (*Labels) Plot

func (l *Labels) Plot(plt *plot.Plot)

Plot implements the Plotter interface, drawing labels.

func (*Labels) XYData

func (l *Labels) XYData() (data plot.XYer, pixels plot.XYer)

type Line

type Line struct {
	// XYs is a copy of the points for this line.
	plot.XYs

	// PXYs is the actual pixel plotting coordinates for each XY value.
	PXYs plot.XYs

	// StepStyle is the kind of the step line.
	StepStyle StepKind

	// LineStyle is the style of the line connecting the points.
	// Use zero width to disable lines.
	LineStyle plot.LineStyle

	// FillColor is the color to fill the area below the plot.
	// Use nil to disable the filling. This is the default.
	FillColor color.Color

	// if true, draw lines that connect points with a negative X-axis direction;
	// otherwise there is a break in the line.
	// default is false, so that repeated series of data across the X axis
	// are plotted separately.
	NegativeXDraw bool
}

Line implements the Plotter interface, drawing a line using XYer data.

func AddTableLine

func AddTableLine(plt *plot.Plot, tab Table, xcolumn, ycolumn int) (*Line, error)

AddTableLine adds Line with given x, y columns from given tabular data

func NewLine

func NewLine(xys plot.XYer) (*Line, error)

NewLine returns a Line that uses the default line style and does not draw glyphs.

func (*Line) DataRange

func (pts *Line) DataRange() (xmin, xmax, ymin, ymax float32)

DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.

func (*Line) Defaults

func (pts *Line) Defaults()

func (*Line) Plot

func (pts *Line) Plot(plt *plot.Plot)

Plot draws the Line, implementing the plot.Plotter interface.

func (*Line) Thumbnail

func (pts *Line) Thumbnail(plt *plot.Plot)

Thumbnail returns the thumbnail for the LineTo, implementing the plot.Thumbnailer interface.

func (*Line) XYData

func (pts *Line) XYData() (data plot.XYer, pixels plot.XYer)

type Scatter

type Scatter struct {
	// XYs is a copy of the points for this scatter.
	plot.XYs

	// PXYs is the actual plotting coordinates for each XY value.
	PXYs plot.XYs

	// size of shape to draw for each point
	PointSize units.Value

	// shape to draw for each point
	PointShape Shapes

	// LineStyle is the style of the line connecting the points.
	// Use zero width to disable lines.
	LineStyle plot.LineStyle
}

Scatter implements the Plotter interface, drawing a shape for each point.

func NewScatter

func NewScatter(xys plot.XYer) (*Scatter, error)

NewScatter returns a Scatter that uses the default glyph style.

func (*Scatter) DataRange

func (pts *Scatter) DataRange() (xmin, xmax, ymin, ymax float32)

DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.

func (*Scatter) Plot

func (pts *Scatter) Plot(plt *plot.Plot)

Plot draws the Line, implementing the plot.Plotter interface.

func (*Scatter) Thumbnail

func (pts *Scatter) Thumbnail(plt *plot.Plot)

Thumbnail the thumbnail for the Scatter, implementing the plot.Thumbnailer interface.

func (*Scatter) XYData

func (pts *Scatter) XYData() (data plot.XYer, pixels plot.XYer)

type Shapes

type Shapes int32 //enums:enum
const (
	// Ring is the outline of a circle
	Ring Shapes = iota

	// Circle is a solid circle
	Circle

	// Square is the outline of a square
	Square

	// Box is a filled square
	Box

	// Triangle is the outline of a triangle
	Triangle

	// Pyramid is a filled triangle
	Pyramid

	// Plus is a plus sign
	Plus

	// Cross is a big X
	Cross
)
const ShapesN Shapes = 8

ShapesN is the highest valid value for type Shapes, plus one.

func ShapesValues

func ShapesValues() []Shapes

ShapesValues returns all possible values for the type Shapes.

func (Shapes) Desc

func (i Shapes) Desc() string

Desc returns the description of the Shapes value.

func (Shapes) Int64

func (i Shapes) Int64() int64

Int64 returns the Shapes value as an int64.

func (Shapes) MarshalText

func (i Shapes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Shapes) SetInt64

func (i *Shapes) SetInt64(in int64)

SetInt64 sets the Shapes value from an int64.

func (*Shapes) SetString

func (i *Shapes) SetString(s string) error

SetString sets the Shapes value from its string representation, and returns an error if the string is invalid.

func (Shapes) String

func (i Shapes) String() string

String returns the string representation of this Shapes value.

func (*Shapes) UnmarshalText

func (i *Shapes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Shapes) Values

func (i Shapes) Values() []enums.Enum

Values returns all possible values for the type Shapes.

type StepKind

type StepKind int32 //enums:enum

StepKind specifies a form of a connection of two consecutive points.

const (
	// NoStep connects two points by simple line
	NoStep StepKind = iota

	// PreStep connects two points by following lines: vertical, horizontal.
	PreStep

	// MidStep connects two points by following lines: horizontal, vertical, horizontal.
	// Vertical line is placed in the middle of the interval.
	MidStep

	// PostStep connects two points by following lines: horizontal, vertical.
	PostStep
)
const StepKindN StepKind = 4

StepKindN is the highest valid value for type StepKind, plus one.

func StepKindValues

func StepKindValues() []StepKind

StepKindValues returns all possible values for the type StepKind.

func (StepKind) Desc

func (i StepKind) Desc() string

Desc returns the description of the StepKind value.

func (StepKind) Int64

func (i StepKind) Int64() int64

Int64 returns the StepKind value as an int64.

func (StepKind) MarshalText

func (i StepKind) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*StepKind) SetInt64

func (i *StepKind) SetInt64(in int64)

SetInt64 sets the StepKind value from an int64.

func (*StepKind) SetString

func (i *StepKind) SetString(s string) error

SetString sets the StepKind value from its string representation, and returns an error if the string is invalid.

func (StepKind) String

func (i StepKind) String() string

String returns the string representation of this StepKind value.

func (*StepKind) UnmarshalText

func (i *StepKind) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (StepKind) Values

func (i StepKind) Values() []enums.Enum

Values returns all possible values for the type StepKind.

type Table

type Table interface {
	// number of columns of data
	NumColumns() int

	//	name of given column
	ColumnName(i int) string

	//	number of rows of data
	NumRows() int

	// PlotData returns the data value at given column and row
	PlotData(column, row int) float32
}

Table is an interface for tabular data for plotting, with columns of values.

type TableXYer

type TableXYer struct {
	Table Table

	// the indexes of the tensor columns to use for the X and Y data, respectively
	XColumn, YColumn int
}

TableXYer is an interface for providing XY access to Table data

func NewTableXYer

func NewTableXYer(tab Table, xcolumn, ycolumn int) *TableXYer

func (*TableXYer) Len

func (dt *TableXYer) Len() int

func (*TableXYer) XY

func (dt *TableXYer) XY(i int) (x, y float32)

type XErrorBars

type XErrorBars struct {
	// XYs is a copy of the points for this line.
	plot.XYs

	// XErrors is a copy of the X errors for each point.
	XErrors

	// PXYs is the actual pixel plotting coordinates for each XY value,
	// representing the high, center value of the error bar.
	PXYs plot.XYs

	// LineStyle is the style used to draw the error bars.
	LineStyle plot.LineStyle

	// CapWidth is the width of the caps drawn at the top
	// of each error bar.
	CapWidth units.Value
}

XErrorBars implements the plot.Plotter, plot.DataRanger, and plot.GlyphBoxer interfaces, drawing horizontal error bars, denoting error in Y values.

func NewXErrorBars

func NewXErrorBars(xerrs interface {
	plot.XYer
	XErrorer
}) (*XErrorBars, error)

Returns a new XErrorBars plotter, or an error on failure. The error values from the XErrorer interface are interpreted as relative to the corresponding X value. The errors for a given X value are computed by taking the absolute value of the error returned by the XErrorer and subtracting the first and adding the second to the X value.

func (*XErrorBars) DataRange

func (e *XErrorBars) DataRange() (xmin, xmax, ymin, ymax float32)

DataRange implements the plot.DataRanger interface.

func (*XErrorBars) Defaults

func (eb *XErrorBars) Defaults()

func (*XErrorBars) Plot

func (e *XErrorBars) Plot(plt *plot.Plot)

Plot implements the Plotter interface, drawing labels.

func (*XErrorBars) XYData

func (e *XErrorBars) XYData() (data plot.XYer, pixels plot.XYer)

type XErrorer

type XErrorer interface {
	// XError returns Low, High error values for X data.
	XError(i int) (low, high float32)
}

XErrorer provides an interface for a list of Low, High error bar values. This is used in addition to an XYer interface, if implemented.

type XErrors

type XErrors Errors

XErrors implements the XErrorer interface.

func (XErrors) XError

func (xe XErrors) XError(i int) (low, high float32)

type XYLabeller

type XYLabeller interface {
	plot.XYer
	plot.Labeller
}

XYLabeller combines the XYer and Labeller types. this is

type XYLabels

type XYLabels struct {
	plot.XYs
	Labels []string
}

XYLabels holds XY data with labels. The ith label corresponds to the ith XY.

func (XYLabels) Label

func (l XYLabels) Label(i int) string

Label returns the label for point index i.

type YErrorBars

type YErrorBars struct {
	// XYs is a copy of the points for this line.
	plot.XYs

	// YErrors is a copy of the Y errors for each point.
	YErrors

	// PXYs is the actual pixel plotting coordinates for each XY value,
	// representing the high, center value of the error bar.
	PXYs plot.XYs

	// LineStyle is the style used to draw the error bars.
	LineStyle plot.LineStyle

	// CapWidth is the width of the caps drawn at the top of each error bar.
	CapWidth units.Value
}

YErrorBars implements the plot.Plotter, plot.DataRanger, and plot.GlyphBoxer interfaces, drawing vertical error bars, denoting error in Y values.

func NewYErrorBars

func NewYErrorBars(yerrs interface {
	plot.XYer
	YErrorer
}) (*YErrorBars, error)

NewYErrorBars returns a new YErrorBars plotter, or an error on failure. The error values from the YErrorer interface are interpreted as relative to the corresponding Y value. The errors for a given Y value are computed by taking the absolute value of the error returned by the YErrorer and subtracting the first and adding the second to the Y value.

func (*YErrorBars) DataRange

func (e *YErrorBars) DataRange() (xmin, xmax, ymin, ymax float32)

DataRange implements the plot.DataRanger interface.

func (*YErrorBars) Defaults

func (eb *YErrorBars) Defaults()

func (*YErrorBars) Plot

func (e *YErrorBars) Plot(plt *plot.Plot)

Plot implements the Plotter interface, drawing labels.

func (*YErrorBars) XYData

func (e *YErrorBars) XYData() (data plot.XYer, pixels plot.XYer)

type YErrorer

type YErrorer interface {
	// YError returns two error values for Y data.
	YError(i int) (float32, float32)
}

YErrorer provides an interface for YError method. This is used in addition to an XYer interface, if implemented.

type YErrors

type YErrors Errors

YErrors implements the YErrorer interface.

func (YErrors) YError

func (ye YErrors) YError(i int) (float32, float32)

Jump to

Keyboard shortcuts

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