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 ¶
- func AddTableLinePoints(plt *plot.Plot, tab Table, xcolumn, ycolumn int) (*Line, *Scatter, error)
- func DrawBox(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawCircle(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawCross(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawPlus(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawPyramid(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawRing(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawShape(pc *paint.Context, pos math32.Vector2, size float32, shape Shapes)
- func DrawSquare(pc *paint.Context, pos math32.Vector2, size float32)
- func DrawTriangle(pc *paint.Context, pos math32.Vector2, size float32)
- func NewLinePoints(xys plot.XYer) (*Line, *Scatter, error)
- func TableColumnIndex(tab Table, name string) int
- type BarChart
- func (b *BarChart) BarHeight(i int) float32
- func (b *BarChart) DataRange(plt *plot.Plot) (xmin, xmax, ymin, ymax float32)
- func (b *BarChart) Defaults()
- func (b *BarChart) Plot(plt *plot.Plot)
- func (b *BarChart) StackOn(on *BarChart)
- func (b *BarChart) Thumbnail(plt *plot.Plot)
- func (b *BarChart) XYData() (data plot.XYer, pixels plot.XYer)
- type Errors
- type Labels
- type Line
- type Scatter
- type Shapes
- func (i Shapes) Desc() string
- func (i Shapes) Int64() int64
- func (i Shapes) MarshalText() ([]byte, error)
- func (i *Shapes) SetInt64(in int64)
- func (i *Shapes) SetString(s string) error
- func (i Shapes) String() string
- func (i *Shapes) UnmarshalText(text []byte) error
- func (i Shapes) Values() []enums.Enum
- type StepKind
- func (i StepKind) Desc() string
- func (i StepKind) Int64() int64
- func (i StepKind) MarshalText() ([]byte, error)
- func (i *StepKind) SetInt64(in int64)
- func (i *StepKind) SetString(s string) error
- func (i StepKind) String() string
- func (i *StepKind) UnmarshalText(text []byte) error
- func (i StepKind) Values() []enums.Enum
- type Table
- type TableXYer
- type XErrorBars
- type XErrorer
- type XErrors
- type XYLabeler
- type XYLabels
- type YErrorBars
- type YErrorer
- type YErrors
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTableLinePoints ¶
AddTableLinePoints adds Line w/ Points with given x, y columns from given tabular data
func NewLinePoints ¶
NewLinePoints returns both a Line and a Scatter plot for the given point data.
func TableColumnIndex ¶
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 image.Image // 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 ¶
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 ¶
BarHeight returns the maximum y value of the ith bar, taking into account any bars upon which it is stacked.
func (*BarChart) StackOn ¶
StackOn stacks a bar chart on top of another, and sets the bar positioning options to that of the chart upon which it is being stacked.
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 // contains filtered or unexported fields }
Labels implements the Plotter interface, drawing a set of labels at specified points.
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 // Fill is the color to fill the area below the plot. // Use nil to disable filling, which is the default. Fill image.Image // 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 ¶
AddTableLine adds Line with given x, y columns from given tabular data
func (*Line) DataRange ¶
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
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 ¶
NewScatter returns a Scatter that uses the default glyph style.
func (*Scatter) DataRange ¶
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
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) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Shapes) SetString ¶
SetString sets the Shapes value from its string representation, and returns an error if the string is invalid.
func (*Shapes) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
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) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*StepKind) SetString ¶
SetString sets the StepKind value from its string representation, and returns an error if the string is invalid.
func (*StepKind) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
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 ¶
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(plt *plot.Plot) (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.
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 XYLabeler ¶ added in v0.2.3
XYLabeler combines the plot.XYer and plot.Labeler types.
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(plt *plot.Plot) (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.