plots

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: BSD-3-Clause Imports: 8 Imported by: 1

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

View Source
const (
	// YErrorBarsType is be used for specifying the type name.
	YErrorBarsType = "YErrorBars"

	// XErrorBarsType is be used for specifying the type name.
	XErrorBarsType = "XErrorBars"
)
View Source
const BarType = "Bar"

BarType is be used for specifying the type name.

View Source
const LabelsType = "Labels"

LabelsType is be used for specifying the type name.

View Source
const XYType = "XY"

XYType is be used for specifying the type name.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	// copies of data
	Y, Err plot.Values

	// actual plotting X, Y values in data coordinates, taking into account stacking etc.
	X, Yp plot.Values

	// PX, PY are the actual pixel plotting coordinates for each XY value.
	PX, PY []float32

	// Style has the properties used to render the bars.
	Style plot.Style

	// 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 *Bar
	// contains filtered or unexported fields
}

A Bar 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 the High data role.

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 NewBar

func NewBar(plt *plot.Plot, data any) *Bar

NewBar adds a new bar plotter with a single bar for each value, for given data which can either by a plot.Valuer (e.g., Tensor) with the Y values, or a plot.Data with roles, and values defined. 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 using the High data role. Styler functions are obtained from the Y metadata if present.

func (*Bar) ApplyStyle

func (bc *Bar) ApplyStyle(ps *plot.PlotStyle, idx int)

func (*Bar) BarHeight

func (bc *Bar) BarHeight(i int) float64

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

func (*Bar) Data

func (bc *Bar) Data() (data plot.Data, pixX, pixY []float32)

func (*Bar) Defaults

func (bc *Bar) Defaults()

func (*Bar) Plot

func (bc *Bar) Plot(plt *plot.Plot)

Plot implements the plot.Plotter interface.

func (*Bar) StackOn

func (bc *Bar) StackOn(on *Bar)

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.

func (*Bar) Styler

func (bc *Bar) Styler(f func(s *plot.Style)) *Bar

func (*Bar) Stylers

func (bc *Bar) Stylers() *plot.Stylers

func (*Bar) Thumbnail

func (bc *Bar) Thumbnail(plt *plot.Plot)

Thumbnail fulfills the plot.Thumbnailer interface.

func (*Bar) UpdateRange

func (bc *Bar) UpdateRange(plt *plot.Plot, x, y, yr, z *minmax.F64)

UpdateRange updates the given ranges.

type Labels

type Labels struct {
	// copies of data for this line
	X, Y   plot.Values
	Labels plot.Labels

	// PX, PY are the actual pixel plotting coordinates for each XY value.
	PX, PY []float32

	// Style is the style of the label text.
	Style plot.Style
	// contains filtered or unexported fields
}

Labels draws text labels at specified X, Y points.

func NewLabels

func NewLabels(plt *plot.Plot, data plot.Data) *Labels

NewLabels adds a new Labels to given plot for given data, which must specify X, Y and Label roles. Styler functions are obtained from the Label metadata if present.

func (*Labels) ApplyStyle

func (lb *Labels) ApplyStyle(ps *plot.PlotStyle, idx int)

func (*Labels) Data

func (lb *Labels) Data() (data plot.Data, pixX, pixY []float32)

func (*Labels) Defaults

func (lb *Labels) Defaults()

func (*Labels) Plot

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

Plot implements the Plotter interface, drawing labels.

func (*Labels) Styler

func (lb *Labels) Styler(f func(s *plot.Style)) *Labels

Styler adds a style function to set style parameters.

func (*Labels) Stylers

func (lb *Labels) Stylers() *plot.Stylers

func (*Labels) UpdateRange

func (lb *Labels) UpdateRange(plt *plot.Plot, x, y, yr, z *minmax.F64)

UpdateRange updates the given ranges.

type XErrorBars

type XErrorBars struct {
	// copies of data for this line
	X, Y, Low, High plot.Values

	// PX, PY are the actual pixel plotting coordinates for each XY value.
	PX, PY []float32

	// Style is the style for plotting.
	Style plot.Style
	// contains filtered or unexported fields
}

XErrorBars draws horizontal error bars, denoting error in X values, using ether High or Low, High data roles for error deviations around X, Y coordinates.

func NewXErrorBars

func NewXErrorBars(plt *plot.Plot, data plot.Data) *XErrorBars

NewXErrorBars adds a new XErrorBars plotter to given plot, using Low, High data roles for error deviations around X, Y coordinates.

func (*XErrorBars) ApplyStyle

func (eb *XErrorBars) ApplyStyle(ps *plot.PlotStyle, idx int)

func (*XErrorBars) Data

func (eb *XErrorBars) Data() (data plot.Data, pixX, pixY []float32)

func (*XErrorBars) Defaults

func (eb *XErrorBars) Defaults()

func (*XErrorBars) Plot

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

func (*XErrorBars) Styler

func (eb *XErrorBars) Styler(f func(s *plot.Style)) *XErrorBars

Styler adds a style function to set style parameters.

func (*XErrorBars) Stylers

func (eb *XErrorBars) Stylers() *plot.Stylers

func (*XErrorBars) UpdateRange

func (eb *XErrorBars) UpdateRange(plt *plot.Plot, x, y, yr, z *minmax.F64)

UpdateRange updates the given ranges.

type XY

type XY struct {
	// copies of data for this line
	X, Y, Color, Size plot.Values

	// PX, PY are the actual pixel plotting coordinates for each XY value.
	PX, PY []float32

	// Style is the style for plotting.
	Style plot.Style
	// contains filtered or unexported fields
}

XY draws lines between and / or points for XY data values.

func NewLine

func NewLine(plt *plot.Plot, data any) *XY

NewLine adds an XY plot drawing Lines only by default, for given data which can either by a plot.Valuer (e.g., Tensor) with the Y values, or a plot.Data with roles, and values defined. See also NewScatter and NewPointLine.

func NewPointLine

func NewPointLine(plt *plot.Plot, data any) *XY

NewPointLine adds an XY plot drawing both lines and points by default, for given data which can either by a plot.Valuer (e.g., Tensor) with the Y values, or a plot.Data with roles, and values defined. See also NewLine and NewScatter.

func NewScatter

func NewScatter(plt *plot.Plot, data any) *XY

NewScatter adds an XY scatter plot drawing Points only by default, for given data which can either by a plot.Valuer (e.g., Tensor) with the Y values, or a plot.Data with roles, and values defined. See also NewLine and NewPointLine.

func NewXY

func NewXY(plt *plot.Plot, data any) *XY

NewXY adds a new XY plotter to given plot for given data, which can either by a plot.Valuer (e.g., Tensor) with the Y values, or a plot.Data with roles, and values defined. Data can also include Color and / or Size for the points. Styler functions are obtained from the Y metadata if present.

func (*XY) ApplyStyle

func (ln *XY) ApplyStyle(ps *plot.PlotStyle, idx int)

func (*XY) Data

func (ln *XY) Data() (data plot.Data, pixX, pixY []float32)

func (*XY) Defaults

func (ln *XY) Defaults()

func (*XY) Plot

func (ln *XY) Plot(plt *plot.Plot)

Plot does the drawing, implementing the plot.Plotter interface.

func (*XY) SetData added in v0.1.1

func (ln *XY) SetData(data any) error

SetData sets the plot data.

func (*XY) Styler

func (ln *XY) Styler(f func(s *plot.Style)) *XY

Styler adds a style function to set style parameters.

func (*XY) Stylers

func (ln *XY) Stylers() *plot.Stylers

func (*XY) Thumbnail

func (ln *XY) Thumbnail(plt *plot.Plot)

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

func (*XY) UpdateRange

func (ln *XY) UpdateRange(plt *plot.Plot, x, y, yr, z *minmax.F64)

UpdateRange updates the given ranges.

type YErrorBars

type YErrorBars struct {
	// copies of data for this line
	X, Y, Low, High plot.Values

	// PX, PY are the actual pixel plotting coordinates for each XY value.
	PX, PY []float32

	// Style is the style for plotting.
	Style plot.Style
	// contains filtered or unexported fields
}

YErrorBars draws vertical error bars, denoting error in Y values, using ether High or Low, High data roles for error deviations around X, Y coordinates.

func NewYErrorBars

func NewYErrorBars(plt *plot.Plot, data plot.Data) *YErrorBars

NewYErrorBars adds a new YErrorBars plotter to given plot, using Low, High data roles for error deviations around X, Y coordinates. Styler functions are obtained from the High data if present.

func (*YErrorBars) ApplyStyle

func (eb *YErrorBars) ApplyStyle(ps *plot.PlotStyle, idx int)

func (*YErrorBars) Data

func (eb *YErrorBars) Data() (data plot.Data, pixX, pixY []float32)

func (*YErrorBars) Defaults

func (eb *YErrorBars) Defaults()

func (*YErrorBars) Plot

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

func (*YErrorBars) Styler

func (eb *YErrorBars) Styler(f func(s *plot.Style)) *YErrorBars

Styler adds a style function to set style parameters.

func (*YErrorBars) Stylers

func (eb *YErrorBars) Stylers() *plot.Stylers

func (*YErrorBars) UpdateRange

func (eb *YErrorBars) UpdateRange(plt *plot.Plot, x, y, yr, z *minmax.F64)

UpdateRange updates the given ranges.

Jump to

Keyboard shortcuts

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