Documentation ¶
Overview ¶
The plotter package defines a variety of standard Plotters for the Plotinum 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.
New* functions return an error if the data contains Inf, NaN, or is empty. Some of the New* functions return other plotter-specific errors too.
Index ¶
- Variables
- func CheckFloats(fs ...float64) error
- func NewLinePoints(xys XYer) (*Line, *Scatter, error)
- func Range(vs Valuer) (min, max float64)
- func XYRange(xys XYer) (xmin, xmax, ymin, ymax float64)
- type BarChart
- func (b *BarChart) BarHeight(i int) float64
- func (b *BarChart) DataRange() (xmin, xmax, ymin, ymax float64)
- func (b *BarChart) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
- func (b *BarChart) Plot(da plot.DrawArea, plt *plot.Plot)
- func (b *BarChart) StackOn(on *BarChart)
- func (b *BarChart) Thumbnail(da *plot.DrawArea)
- type BoxPlot
- type Bubbles
- type Errors
- type Function
- type GlyphBoxes
- type Grid
- type Histogram
- type HistogramBin
- type HorizBoxPlot
- type HorizQuartPlot
- type Labeller
- type Labels
- type Line
- type QuartPlot
- type Scatter
- type Valuer
- type Values
- type XErrorBars
- type XErrorer
- type XErrors
- type XValues
- type XYValues
- type XYZer
- type XYZs
- type XYer
- type XYs
- type YErrorBars
- type YErrorer
- type YErrors
- type YValues
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultFont is the default font name. DefaultFont = "Times-Roman" // DefaultFontSize is the default font. DefaultFontSize = vg.Points(10) )
var ( // DefaultLineStyle is the default style for drawing // lines. DefaultLineStyle = plot.LineStyle{ Color: color.Black, Width: vg.Points(1), Dashes: []vg.Length{}, DashOffs: 0, } // DefaultGlyphStyle is the default style used // for gyph marks. DefaultGlyphStyle = plot.GlyphStyle{ Color: color.Black, Radius: vg.Points(2.5), Shape: plot.RingGlyph{}, } )
var ( ErrInfinity = errors.New("Infinite data point") ErrNaN = errors.New("NaN data point") ErrNoData = errors.New("No data points") )
var ( // DefaultQuartMedianStyle is a fat dot. DefaultQuartMedianStyle = plot.GlyphStyle{ Color: color.Black, Radius: vg.Points(1.5), Shape: plot.CircleGlyph{}, } // DefaultQuartWhiskerStyle is a hairline. DefaultQuartWhiskerStyle = plot.LineStyle{ Color: color.Black, Width: vg.Points(0.5), Dashes: []vg.Length{}, DashOffs: 0, } )
var DefaultCapWidth = vg.Points(5)
DefaultCapWidth is the default width of error bar caps.
Functions ¶
func CheckFloats ¶
CheckFloats returns an error if any of the arguments are NaN or Infinity.
func NewLinePoints ¶
NewLinePoints returns both a Line and a Points for the given point data.
Types ¶
type BarChart ¶
type BarChart struct { Values // Width is the width of the bars. Width vg.Length // Color is the fill color of the bars. Color color.Color // LineStyle is the style of the outline of the bars. plot.LineStyle // Offset is added to the x location of each bar. // When the Offset is zero, the bars are drawn // centered at their x location. Offset vg.Length // XMin is the X location of the first bar. XMin // can be changed to move groups of bars // down the X axis in order to make grouped // bar charts. XMin float64 // contains filtered or unexported fields }
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.
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) GlyphBoxes ¶
GlyphBoxes implements the GlyphBoxer interface.
type BoxPlot ¶
type BoxPlot struct { // Offset is added to the x location of each box. // When the Offset is zero, the boxes are drawn // centered at their x location. Offset vg.Length // Width is the width used to draw the box. Width vg.Length // CapWidth is the width of the cap used to top // off a whisker. CapWidth vg.Length // GlyphStyle is the style of the outside point glyphs. GlyphStyle plot.GlyphStyle // BoxStyle is the line style for the box. BoxStyle plot.LineStyle // MedianStyle is the line style for the median line. MedianStyle plot.LineStyle // WhiskerStyle is the line style used to draw the // whiskers. WhiskerStyle plot.LineStyle // contains filtered or unexported fields }
BoxPlot implements the Plotter interface, drawing a boxplot to represent the distribution of values.
func NewBoxPlot ¶
NewBoxPlot returns a new BoxPlot that represents the distribution of the given values. The style of the box plot is that used for Tukey's schematic plots is “Exploratory Data Analysis.”
An error is returned if the boxplot is created with no values.
The fence values are 1.5x the interquartile before the first quartile and after the third quartile. Any value that is outside of the fences are drawn as Outside points. The adjacent values (to which the whiskers stretch) are the minimum and maximum values that are not outside the fences.
func (*BoxPlot) DataRange ¶
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
func (*BoxPlot) GlyphBoxes ¶
GlyphBoxes returns a slice of GlyphBoxes for the points and for the median line of the boxplot, implementing the plot.GlyphBoxer interface
func (*BoxPlot) OutsideLabels ¶
OutsideLabels returns a *Labels that will plot a label for each of the outside points. The labels are assumed to correspond to the points used to create the box plot.
type Bubbles ¶
type Bubbles struct { XYZs // Color is the color of the bubbles. color.Color // MinRadius and MaxRadius give the minimum // and maximum bubble radius respectively. // The radii of each bubble is interpolated linearly // between these two values. MinRadius, MaxRadius vg.Length // MinZ and MaxZ are the minimum and // maximum Z values from the data. MinZ, MaxZ float64 }
Bubbles implements the Plotter interface, drawing a bubble plot of x, y, z triples where the z value determines the radius of the bubble.
func NewBubbles ¶
NewBubbles creates as new bubble plot plotter for the given data, with a minimum and maximum bubble radius.
func (*Bubbles) DataRange ¶
DataRange implements the DataRange method of the plot.DataRanger interface.
func (*Bubbles) GlyphBoxes ¶
GlyphBoxes implements the GlyphBoxes method of the plot.GlyphBoxer interface.
type Errors ¶
type Errors []struct{ Low, High float64 }
Errors is a slice of low and high error values.
type Function ¶
Function implements the Plotter interface, drawing a line for the given function.
func NewFunction ¶
NewFunction returns a Function that plots F using the default line style with 50 samples.
type GlyphBoxes ¶
GlyphBoxes implements the Plotter interface, drawing all of the glyph boxes of the plot. This is intended for debugging.
func NewGlyphBoxes ¶
func NewGlyphBoxes() *GlyphBoxes
type Grid ¶
type Grid struct { // Vertical is the style of the vertical lines. Vertical plot.LineStyle // Horizontal is the style of the horizontal lines. Horizontal plot.LineStyle }
Grid implements the plot.Plotter interface, drawing a set of grid lines at the major tick marks.
type Histogram ¶
type Histogram struct { // Bins is the set of bins for this histogram. Bins []HistogramBin // Width is the width of each bin. Width float64 // FillColor is the color used to fill each // bar of the histogram. If the color is nil // then the bars are not filled. FillColor color.Color // LineStyle is the style of the outline of each // bar of the histogram. plot.LineStyle }
Histogram implements the Plotter interface, drawing a histogram of the data.
func NewHist ¶
NewHist returns a new histogram, as in NewHistogram, except that it accepts a Valuer instead of an XYer.
func NewHistogram ¶
NewHistogram returns a new histogram that represents the distribution of values using the given number of bins.
Each y value is assumed to be the frequency count for the corresponding x.
If the number of bins is non-positive than a reasonable default is used.
type HistogramBin ¶
A HistogramBin approximates the number of values within a range by a single number (the weight).
type HorizBoxPlot ¶
type HorizBoxPlot struct{ *BoxPlot }
HorizBoxPlot is like a regular BoxPlot, however, it draws horizontally instead of Vertically.
func MakeHorizBoxPlot ¶
MakeHorizBoxPlot returns a HorizBoxPlot, plotting the values in a horizontal box plot centered along a fixed location of the y axis.
func (HorizBoxPlot) DataRange ¶
func (b HorizBoxPlot) DataRange() (float64, float64, float64, float64)
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
func (HorizBoxPlot) GlyphBoxes ¶
func (b HorizBoxPlot) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
GlyphBoxes returns a slice of GlyphBoxes for the points and for the median line of the boxplot, implementing the plot.GlyphBoxer interface
func (*HorizBoxPlot) OutsideLabels ¶
func (b *HorizBoxPlot) OutsideLabels(labels Labeller) (*Labels, error)
OutsideLabels returns a *Labels that will plot a label for each of the outside points. The labels are assumed to correspond to the points used to create the box plot.
type HorizQuartPlot ¶
type HorizQuartPlot struct{ *QuartPlot }
HorizQuartPlot is like a regular QuartPlot, however, it draws horizontally instead of Vertically.
func MakeHorizQuartPlot ¶
func MakeHorizQuartPlot(loc float64, vs Valuer) (HorizQuartPlot, error)
MakeHorizQuartPlot returns a HorizQuartPlot, plotting the values in a horizontal plot centered along a fixed location of the y axis.
func (HorizQuartPlot) DataRange ¶
func (b HorizQuartPlot) DataRange() (float64, float64, float64, float64)
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
func (HorizQuartPlot) GlyphBoxes ¶
func (b HorizQuartPlot) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
GlyphBoxes returns a slice of GlyphBoxes for the plot, implementing the plot.GlyphBoxer interface.
func (*HorizQuartPlot) OutsideLabels ¶
func (b *HorizQuartPlot) OutsideLabels(labels Labeller) (*Labels, error)
OutsideLabels returns a *Labels that will plot a label for each of the outside points. The labels are assumed to correspond to the points used to create the plot.
type Labels ¶
type Labels struct { XYs // Labels is the set of labels corresponding // to each point. Labels []string // TextStyle is the style of the label text. plot.TextStyle // XAlign and YAlign are multiplied by the width // and height of each label respectively and the // added to the final location. E.g., XAlign=-0.5 // and YAlign=-0.5 centers the label at the given // X, Y location, and XAlign=0, YAlign=0 aligns // the text to the left of the point, and XAlign=-1, // YAlign=0 aligns the text to the right of the point. XAlign, YAlign float64 // XOffset and YOffset are added directly to the final // label X and Y location respectively. XOffset, YOffset vg.Length }
Labels implements the Plotter interface, drawing a set of labels at specified points.
func (*Labels) GlyphBoxes ¶
GlyphBoxes returns a slice of GlyphBoxes, one for each of the labels, implementing the plot.GlyphBoxer interface.
type Line ¶
type Line struct { // XYs is a copy of the points for this line. XYs // LineStyle is the style of the line connecting // the points. plot.LineStyle // ShadeColor is the color of the shaded area. ShadeColor *color.Color }
Line implements the Plotter interface, drawing a line.
func (*Line) DataRange ¶
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
type QuartPlot ¶
type QuartPlot struct { // Offset is added to the x location of each plot. // When the Offset is zero, the plot is drawn // centered at its x location. Offset vg.Length // MedianStyle is the line style for the median point. MedianStyle plot.GlyphStyle // WhiskerStyle is the line style used to draw the // whiskers. WhiskerStyle plot.LineStyle // contains filtered or unexported fields }
QuartPlot implements the Plotter interface, drawing a plot to represent the distribution of values.
This style of the plot appears in Tufte's "The Visual Display of Quantitative Information".
func NewQuartPlot ¶
NewQuartPlot returns a new QuartPlot that represents the distribution of the given values.
An error is returned if the plot is created with no values.
The fence values are 1.5x the interquartile before the first quartile and after the third quartile. Any value that is outside of the fences are drawn as Outside points. The adjacent values (to which the whiskers stretch) are the minimum and maximum values that are not outside the fences.
func (*QuartPlot) DataRange ¶
DataRange returns the minimum and maximum x and y values, implementing the plot.DataRanger interface.
func (*QuartPlot) GlyphBoxes ¶
GlyphBoxes returns a slice of GlyphBoxes for the plot, implementing the plot.GlyphBoxer interface.
func (*QuartPlot) OutsideLabels ¶
OutsideLabels returns a *Labels that will plot a label for each of the outside points. The labels are assumed to correspond to the points used to create the plot.
type Scatter ¶
type Scatter struct { // XYs is a copy of the points for this scatter. XYs // GlyphStyle is the style of the glyphs drawn // at each point. plot.GlyphStyle }
Scatter implements the Plotter interface, drawing a glyph for each of a set of points.
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.
func (*Scatter) GlyphBoxes ¶
GlyphBoxes returns a slice of plot.GlyphBoxes, implementing the plot.GlyphBoxer interface.
type Valuer ¶
type Valuer interface { // Len returns the number of values. Len() int // Value returns a value. Value(int) float64 }
Valuer wraps the Len and Value methods.
type Values ¶
type Values []float64
Values implements the Valuer interface.
func CopyValues ¶
CopyValues returns a Values that is a copy of the values from a Valuer, or an error if there are no values, or if one of the copied values is a NaN or Infinity.
type XErrorBars ¶
type XErrorBars struct { XYs // XErrors is a copy of the X errors for each point. XErrors // LineStyle is the style used to draw the error bars. plot.LineStyle // CapWidth is the width of the caps drawn at the top // of each error bar. CapWidth vg.Length }
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 { 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 float64)
DataRange implements the plot.DataRanger interface.
func (*XErrorBars) GlyphBoxes ¶
func (e *XErrorBars) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
GlyphBoxes implements the plot.GlyphBoxer interface.
type XErrorer ¶
type XErrorer interface { // XError returns two error values for X data. XError(int) (float64, float64) }
XErrorer wraps the XError method.
type XValues ¶
type XValues struct {
XYer
}
XValues implements the Valuer interface, returning the x value from an XYer.
type XYValues ¶
type XYValues struct{ XYZer }
XYValues implements the XYer interface, returning the x and y values from an XYZer.
type XYZer ¶
type XYZer interface { // Len returns the number of x, y, z triples. Len() int // XYZ returns an x, y, z triple. XYZ(int) (float64, float64, float64) }
XYZer wraps the Len and XYZ methods.
type XYZs ¶
type XYZs []struct{ X, Y, Z float64 }
XYZs implements the XYZer interface using a slice.
type XYer ¶
type XYer interface { // Len returns the number of x, y pairs. Len() int // XY returns an x, y pair. XY(int) (x, y float64) }
XYer wraps the Len and XY methods.
type XYs ¶
type XYs []struct{ X, Y float64 }
XYs implements the XYer interface.
type YErrorBars ¶
type YErrorBars struct { XYs // YErrors is a copy of the Y errors for each point. YErrors // LineStyle is the style used to draw the error bars. plot.LineStyle // CapWidth is the width of the caps drawn at the top // of each error bar. CapWidth vg.Length }
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 { XYer YErrorer }) (*YErrorBars, error)
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 float64)
DataRange implements the plot.DataRanger interface.
func (*YErrorBars) GlyphBoxes ¶
func (e *YErrorBars) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
GlyphBoxes implements the plot.GlyphBoxer interface.
type YErrorer ¶
type YErrorer interface { // YError returns two error values for Y data. YError(int) (float64, float64) }
YErrorer wraps the YError method.