plot

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: 35 Imported by: 22

README

Plot

See the Cogent Lab Docs for full documentation.

Design discussion

The plot package generates 2D plots of data using the Cogent Core paint rendering system. The plotcore sub-package has Cogent Core Widgets that can be used in applications.

  • Plot is just a wrapper around a plot.Plot, for code-generated plots.
  • Editor is an interactive plot viewer that supports selection of which data to plot, and GUI configuration of plot parameters.

plot is designed to work in two potentially-conflicting ways:

  • Code-based creation of a specific plot with specific data.
  • GUI-based configuration of plots based on a tensor.Table of data columns (via Editor).

The GUI constraint requires a more systematic, factorial organization of the space of possible plot data and how it is organized to create a plot, so that it can be configured with a relatively simple set of GUI settings. The overall logic is as follows:

  • The overall plot has a single shared range of X, Y and optionally Z coordinate ranges (under the corresponding Axis field), that defines where a data value in any plot type is plotted. These ranges are set based on the DataRanger interface.

  • Plot content is driven by Plotter elements that each consume one or more sets of data, which is provided by a Valuer interface that maps onto a minimal subset of the tensor.Tensor interface, so a tensor directly satisfies the interface.

  • Each Plotter element can generally handle multiple different data elements, that are index-aligned. For example, the basic XY plotter requires a Y Valuer, and typically an X, but indexes will be used if it is not present. It optionally uses Size or Color Valuers that apply to the Point elements. A Bar gets at least a Y but also optionally a High Valuer for an error bar. The plot.Data = map[Roles]Valuer is used to create new Plotter elements, allowing an unordered and explicit way of specifying the Roles of each Valuer item. Each Plotter also allows a single Valuer (i.e., Tensor) argument instead of the data, for a convenient minimal plot cse. There are also shortcut methods for NewXY and NewY.

The table-driven plotting case uses a Group name along with the Roles type (X, Y etc) and Plotter type names to organize different plots based on Style settings. Columns with the same Group name all provide data to the same plotter using their different Roles, making it easy to configure various statistical plots of multiple series of grouped data.

Different plotter types (including custom ones) are registered along with their accepted input roles, to allow any type of plot to be generated.

History

The code is adapted from the gonum plot package (which in turn was adapted from google's plotinum, to use the Cogent Core styles and paint rendering framework, which also supports SVG output of the rendering.

Here is the copyright notice for that package:

// Copyright ©2015 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

TODO

  • Min / Max not just for extending but also limiting the range -- currently doesn't do

  • tensor index

  • Grid? in styling.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInfinity = errors.New("plotter: infinite data point")
	ErrNoData   = errors.New("plotter: no data points")
)
View Source
var DefaultFontFamily = rich.SansSerif

DefaultFontFamily specifies a default font family for plotting. if not set, the standard Cogent Core default font is used.

View Source
var Plotters = map[string]PlotterType{}

Plotters is the registry of Plotter types.

View Source
var UTCUnixTime = UnixTimeIn(time.UTC)

UTCUnixTime is the default time conversion for TimeTicks.

Functions

func CheckFloats

func CheckFloats(fs ...float64) error

CheckFloats returns an error if any of the arguments are Infinity. or if there are no non-NaN data points available for plotting.

func CheckNaNs

func CheckNaNs(fs ...float64) bool

CheckNaNs returns true if any of the floats are NaN

func DrawBox

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

func DrawCircle

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

func DrawCross

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

func DrawPlus

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

func DrawPyramid

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

func DrawRing

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

func DrawSquare

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

func DrawTriangle

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

func PlotX

func PlotX(plt *Plot, data Valuer) []float32

PlotX returns plot pixel X coordinate values for given data.

func PlotY

func PlotY(plt *Plot, data Valuer) []float32

PlotY returns plot pixel Y coordinate values for given data.

func PlotYR added in v0.1.1

func PlotYR(plt *Plot, data Valuer) []float32

PlotYR returns plot pixel YR right axis coordinate values for given data.

func Range

func Range(data Valuer, rng *minmax.F64)

Range updates given Range with values from data.

func RangeClamp

func RangeClamp(data Valuer, axisRng *minmax.F64, styleRng *minmax.Range64)

RangeClamp updates the given axis Min, Max range values based on the range of values in the given Data, and the given style range.

func RegisterPlotter

func RegisterPlotter(name, doc string, required, optional []Roles, newFun func(plt *Plot, data Data) Plotter)

RegisterPlotter registers a plotter type.

func SetFirstStyler

func SetFirstStyler(obj any, f func(s *Style))

SetFirstStyler sets the Styler function into given object's metadata, only if there are no other stylers present. This is important for cases where code may be run multiple times on the same object, and you don't want to add multiple redundant style functions (and [plotcore.Editor] is being used).

func SetStyler

func SetStyler(obj any, st ...func(s *Style))

SetStyler sets the Stylers function(s) into given object's metadata. This overwrites any existing styler functions. The [plotcore.Editor] depends on adding a styler function on top of any existing ones, so it is better to use [SetFirstStyle] if that is being used.

func Styler

func Styler(obj any, f func(s *Style))

Styler adds the given Styler function into given object's metadata.

func UnixTimeIn

func UnixTimeIn(loc *time.Location) func(t float64) time.Time

UnixTimeIn returns a time conversion function for the given location.

Types

type Axis

type Axis struct {

	// Range has the Min, Max range of values for the axis (in raw data units.)
	Range minmax.F64

	// specifies which axis this is: X, Y or Z.
	Axis math32.Dims

	// For a Y axis, this puts the axis on the right (i.e., the second Y axis).
	RightY bool

	// Label for the axis.
	Label Text

	// Style has the style parameters for the Axis.
	Style AxisStyle

	// TickText is used for rendering the tick text labels.
	TickText Text

	// Ticker generates the tick marks. Any tick marks
	// returned by the Marker function that are not in
	// range of the axis are not drawn.
	Ticker Ticker

	// Scale transforms a value given in the data coordinate system
	// to the normalized coordinate system of the axis—its distance
	// along the axis as a fraction of the axis range.
	Scale Normalizer

	// AutoRescale enables an axis to automatically adapt its minimum
	// and maximum boundaries, according to its underlying Ticker.
	AutoRescale bool
	// contains filtered or unexported fields
}

Axis represents either a horizontal or vertical axis of a plot. This is the "internal" data structure and should not be used for styling.

func (*Axis) Defaults

func (ax *Axis) Defaults(dim math32.Dims)

Sets Defaults, range is (∞, ­∞), and thus any finite value is less than Min and greater than Max.

func (*Axis) Norm

func (ax *Axis) Norm(x float64) float64

Norm returns the value of x, given in the data coordinate system, normalized to its distance as a fraction of the range of this axis. For example, if x is a.Min then the return value is 0, and if x is a.Max then the return value is 1.

func (*Axis) SanitizeRange

func (ax *Axis) SanitizeRange()

SanitizeRange ensures that the range of the axis makes sense.

type AxisScales

type AxisScales int32 //enums:enum

AxisScales are the scaling options for how values are distributed along an axis: Linear, Log, etc.

const (
	// Linear is a linear axis scale.
	Linear AxisScales = iota

	// Log is a Logarithmic axis scale.
	Log

	// InverseLinear is an inverted linear axis scale.
	InverseLinear

	// InverseLog is an inverted log axis scale.
	InverseLog
)
const AxisScalesN AxisScales = 4

AxisScalesN is the highest valid value for type AxisScales, plus one.

func AxisScalesValues

func AxisScalesValues() []AxisScales

AxisScalesValues returns all possible values for the type AxisScales.

func (AxisScales) Desc

func (i AxisScales) Desc() string

Desc returns the description of the AxisScales value.

func (AxisScales) Int64

func (i AxisScales) Int64() int64

Int64 returns the AxisScales value as an int64.

func (AxisScales) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*AxisScales) SetInt64

func (i *AxisScales) SetInt64(in int64)

SetInt64 sets the AxisScales value from an int64.

func (*AxisScales) SetString

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

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

func (AxisScales) String

func (i AxisScales) String() string

String returns the string representation of this AxisScales value.

func (*AxisScales) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (AxisScales) Values

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

Values returns all possible values for the type AxisScales.

type AxisStyle

type AxisStyle struct {

	// On determines whether the axis is rendered.
	On bool

	// Text has the text style parameters for the text label.
	Text TextStyle

	// Line has styling properties for the axis line.
	Line LineStyle

	// Padding between the axis line and the data.  Having
	// non-zero padding ensures that the data is never drawn
	// on the axis, thus making it easier to see.
	Padding units.Value

	// NTicks is the desired number of ticks (actual likely
	// will be different). If < 2 then the axis will not be drawn.
	NTicks int

	// Scale specifies how values are scaled along the axis:
	// Linear, Log, Inverted
	Scale AxisScales

	// TickText has the text style for rendering tick labels,
	// and is shared for actual rendering.
	TickText TextStyle

	// TickLine has line style for drawing tick lines.
	TickLine LineStyle

	// TickLength is the length of tick lines.
	TickLength units.Value
}

AxisStyle has style properties for the axis.

func (*AxisStyle) Defaults

func (ax *AxisStyle) Defaults()

func (*AxisStyle) SetLine

func (t *AxisStyle) SetLine(v LineStyle) *AxisStyle

SetLine sets the [AxisStyle.Line]: Line has styling properties for the axis line.

func (*AxisStyle) SetNTicks

func (t *AxisStyle) SetNTicks(v int) *AxisStyle

SetNTicks sets the [AxisStyle.NTicks]: NTicks is the desired number of ticks (actual likely will be different). If < 2 then the axis will not be drawn.

func (*AxisStyle) SetOn

func (t *AxisStyle) SetOn(v bool) *AxisStyle

SetOn sets the [AxisStyle.On]: On determines whether the axis is rendered.

func (*AxisStyle) SetPadding

func (t *AxisStyle) SetPadding(v units.Value) *AxisStyle

SetPadding sets the [AxisStyle.Padding]: Padding between the axis line and the data. Having non-zero padding ensures that the data is never drawn on the axis, thus making it easier to see.

func (*AxisStyle) SetScale

func (t *AxisStyle) SetScale(v AxisScales) *AxisStyle

SetScale sets the [AxisStyle.Scale]: Scale specifies how values are scaled along the axis: Linear, Log, Inverted

func (*AxisStyle) SetText

func (t *AxisStyle) SetText(v TextStyle) *AxisStyle

SetText sets the [AxisStyle.Text]: Text has the text style parameters for the text label.

func (*AxisStyle) SetTickLength

func (t *AxisStyle) SetTickLength(v units.Value) *AxisStyle

SetTickLength sets the [AxisStyle.TickLength]: TickLength is the length of tick lines.

func (*AxisStyle) SetTickLine

func (t *AxisStyle) SetTickLine(v LineStyle) *AxisStyle

SetTickLine sets the [AxisStyle.TickLine]: TickLine has line style for drawing tick lines.

func (*AxisStyle) SetTickText

func (t *AxisStyle) SetTickText(v TextStyle) *AxisStyle

SetTickText sets the [AxisStyle.TickText]: TickText has the text style for rendering tick labels, and is shared for actual rendering.

type ConstantTicks

type ConstantTicks []Tick

ConstantTicks is suitable for the Ticker field of an Axis. This function returns the given set of ticks.

func (ConstantTicks) Ticks

func (ts ConstantTicks) Ticks(float64, float64, int) []Tick

Ticks returns Ticks in a specified range

type Data

type Data map[Roles]Valuer

Data is a map of Roles and Data for that Role, providing the primary way of passing data to a Plotter

func DataOrValuer

func DataOrValuer(v any, role Roles) (Data, error)

DataOrValuer processes the given argument which can be either a Data or a Valuer. If the latter, it is returned as a Data with the given Role. This is used for New Plotter methods that can take the default required Valuer, or a Data with roles explicitly defined. If the arg is neither, an error is returned.

func NewXY

func NewXY(x, y Valuer) Data

NewXY returns a new Data with X, Y roles for given values.

func NewY

func NewY(y Valuer) Data

NewY returns a new Data with Y role for given values.

func (Data) CheckLengths

func (dt Data) CheckLengths() error

CheckLengths checks that all the data elements have the same length. Logs and returns an error if not.

type DefaultOffOn

type DefaultOffOn int32 //enums:enum

DefaultOffOn specifies whether to use the default value for a bool option, or to override the default and set Off or On.

const (
	// Default means use the default value.
	Default DefaultOffOn = iota

	// Off means to override the default and turn Off.
	Off

	// On means to override the default and turn On.
	On
)
const DefaultOffOnN DefaultOffOn = 3

DefaultOffOnN is the highest valid value for type DefaultOffOn, plus one.

func DefaultOffOnValues

func DefaultOffOnValues() []DefaultOffOn

DefaultOffOnValues returns all possible values for the type DefaultOffOn.

func (DefaultOffOn) Desc

func (i DefaultOffOn) Desc() string

Desc returns the description of the DefaultOffOn value.

func (DefaultOffOn) Int64

func (i DefaultOffOn) Int64() int64

Int64 returns the DefaultOffOn value as an int64.

func (DefaultOffOn) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*DefaultOffOn) SetInt64

func (i *DefaultOffOn) SetInt64(in int64)

SetInt64 sets the DefaultOffOn value from an int64.

func (*DefaultOffOn) SetString

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

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

func (DefaultOffOn) String

func (i DefaultOffOn) String() string

String returns the string representation of this DefaultOffOn value.

func (*DefaultOffOn) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (DefaultOffOn) Values

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

Values returns all possible values for the type DefaultOffOn.

type DefaultTicks

type DefaultTicks struct{}

DefaultTicks is suitable for the Ticker field of an Axis, it returns a reasonable default set of tick marks.

func (DefaultTicks) Ticks

func (DefaultTicks) Ticks(mn, mx float64, nticks int) []Tick

Ticks returns Ticks in the specified range.

type InvertedScale

type InvertedScale struct{ Normalizer }

InvertedScale can be used as the value of an Axis.Scale function to invert the axis using any Normalizer.

func (InvertedScale) Normalize

func (is InvertedScale) Normalize(min, max, x float64) float64

Normalize returns a normalized [0, 1] value for the position of x.

type Labels

type Labels []string

Labels provides a minimal implementation of the Data interface using a slice of string. It always returns 0 for Float1D.

func (Labels) Float1D

func (lb Labels) Float1D(i int) float64

func (Labels) Len

func (lb Labels) Len() int

func (Labels) String1D

func (lb Labels) String1D(i int) string

type Legend

type Legend struct {

	// Style has the legend styling parameters.
	Style LegendStyle

	// Entries are all of the LegendEntries described by this legend.
	Entries []LegendEntry
}

A Legend gives a description of the meaning of different data elements of the plot. Each legend entry has a name and a thumbnail, where the thumbnail shows a small sample of the display style of the corresponding data.

func (*Legend) Add

func (lg *Legend) Add(name string, thumbs ...Thumbnailer)

Add adds an entry to the legend with the given name. The entry's thumbnail is drawn as the composite of all of the thumbnails.

func (*Legend) Defaults

func (lg *Legend) Defaults()

func (*Legend) LegendForPlotter

func (lg *Legend) LegendForPlotter(plt Plotter) string

LegendForPlotter returns the legend Text for given plotter, if it exists as a Thumbnailer in the legend entries. Otherwise returns empty string.

type LegendEntry

type LegendEntry struct {
	// text is the text associated with this entry.
	Text string

	// thumbs is a slice of all of the thumbnails styles
	Thumbs []Thumbnailer
}

A LegendEntry represents a single line of a legend, it has a name and an icon.

type LegendPosition

type LegendPosition struct {
	// Top and Left specify the location of the legend.
	Top, Left bool

	// XOffs and YOffs are added to the legend's final position,
	// relative to the relevant anchor position
	XOffs, YOffs units.Value
}

LegendPosition specifies where to put the legend

func (*LegendPosition) Defaults

func (lg *LegendPosition) Defaults()

type LegendStyle

type LegendStyle struct {

	// Column is for table-based plotting, specifying the column with legend values.
	Column string

	// Text is the style given to the legend entry texts.
	Text TextStyle `display:"add-fields"`

	// position of the legend
	Position LegendPosition `display:"inline"`

	// ThumbnailWidth is the width of legend thumbnails.
	ThumbnailWidth units.Value `display:"inline"`

	// Fill specifies the background fill color for the legend box,
	// if non-nil.
	Fill image.Image
}

LegendStyle has the styling properties for the Legend.

func (*LegendStyle) Defaults

func (ls *LegendStyle) Defaults()

func (*LegendStyle) SetColumn

func (t *LegendStyle) SetColumn(v string) *LegendStyle

SetColumn sets the [LegendStyle.Column]: Column is for table-based plotting, specifying the column with legend values.

func (*LegendStyle) SetFill

func (t *LegendStyle) SetFill(v image.Image) *LegendStyle

SetFill sets the [LegendStyle.Fill]: Fill specifies the background fill color for the legend box, if non-nil.

func (*LegendStyle) SetPosition

func (t *LegendStyle) SetPosition(v LegendPosition) *LegendStyle

SetPosition sets the [LegendStyle.Position]: position of the legend

func (*LegendStyle) SetText

func (t *LegendStyle) SetText(v TextStyle) *LegendStyle

SetText sets the [LegendStyle.Text]: Text is the style given to the legend entry texts.

func (*LegendStyle) SetThumbnailWidth

func (t *LegendStyle) SetThumbnailWidth(v units.Value) *LegendStyle

SetThumbnailWidth sets the [LegendStyle.ThumbnailWidth]: ThumbnailWidth is the width of legend thumbnails.

type LineStyle

type LineStyle struct {
	// On indicates whether to plot lines.
	On DefaultOffOn

	// Color is the stroke color image specification.
	// Setting to nil turns line off.
	Color image.Image

	// Width is the line width, with a default of 1 Pt (point).
	// Setting to 0 turns line off.
	Width units.Value

	// Dashes are the dashes of the stroke. Each pair of values specifies
	// the amount to paint and then the amount to skip.
	Dashes []float32

	// Fill is the color to fill solid regions, in a plot-specific
	// way (e.g., the area below a Line plot, the bar color).
	// Use nil to disable filling.
	Fill image.Image

	// NegativeX specifies whether to 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.
	NegativeX bool

	// Step specifies how to step the line between points.
	Step StepKind
}

LineStyle has style properties for drawing lines.

func (*LineStyle) Defaults

func (ls *LineStyle) Defaults()

func (*LineStyle) Draw

func (ls *LineStyle) Draw(pt *Plot, start, end math32.Vector2) bool

Draw draws a line between given coordinates, setting the stroke style to current parameters. Returns false if either Width = 0 or Color = nil

func (*LineStyle) HasFill

func (ls *LineStyle) HasFill() bool

func (*LineStyle) SetColor

func (t *LineStyle) SetColor(v image.Image) *LineStyle

SetColor sets the [LineStyle.Color]: Color is the stroke color image specification. Setting to nil turns line off.

func (*LineStyle) SetDashes

func (t *LineStyle) SetDashes(v ...float32) *LineStyle

SetDashes sets the [LineStyle.Dashes]: Dashes are the dashes of the stroke. Each pair of values specifies the amount to paint and then the amount to skip.

func (*LineStyle) SetFill

func (t *LineStyle) SetFill(v image.Image) *LineStyle

SetFill sets the [LineStyle.Fill]: Fill is the color to fill solid regions, in a plot-specific way (e.g., the area below a Line plot, the bar color). Use nil to disable filling.

func (*LineStyle) SetNegativeX

func (t *LineStyle) SetNegativeX(v bool) *LineStyle

SetNegativeX sets the [LineStyle.NegativeX]: NegativeX specifies whether to 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.

func (*LineStyle) SetOn

func (t *LineStyle) SetOn(v DefaultOffOn) *LineStyle

SetOn sets the [LineStyle.On]: On indicates whether to plot lines.

func (*LineStyle) SetStep

func (t *LineStyle) SetStep(v StepKind) *LineStyle

SetStep sets the [LineStyle.Step]: Step specifies how to step the line between points.

func (*LineStyle) SetStroke

func (ls *LineStyle) SetStroke(pt *Plot) bool

SetStroke sets the stroke style in plot paint to current line style. returns false if either the Width = 0 or Color is nil

func (*LineStyle) SetWidth

func (t *LineStyle) SetWidth(v units.Value) *LineStyle

SetWidth sets the [LineStyle.Width]: Width is the line width, with a default of 1 Pt (point). Setting to 0 turns line off.

func (*LineStyle) SpacedColor

func (ls *LineStyle) SpacedColor(idx int)

SpacedColor sets the Color to a default spaced color based on index, if it still has the initial OnSurface default.

func (*LineStyle) SpacedFill

func (ls *LineStyle) SpacedFill(idx int)

SpacedFill sets the Fill to a default spaced color based on index, if it still has the initial nil default.

type LinearScale

type LinearScale struct{}

LinearScale an be used as the value of an Axis.Scale function to set the axis to a standard linear scale.

func (LinearScale) Normalize

func (LinearScale) Normalize(min, max, x float64) float64

Normalize returns the fractional distance of x between min and max.

type LogScale

type LogScale struct{}

LogScale can be used as the value of an Axis.Scale function to set the axis to a log scale.

func (LogScale) Normalize

func (LogScale) Normalize(min, max, x float64) float64

Normalize returns the fractional logarithmic distance of x between min and max.

type LogTicks

type LogTicks struct {
	// Prec specifies the precision of tick rendering
	// according to the documentation for strconv.FormatFloat.
	Prec int
}

LogTicks is suitable for the Ticker field of an Axis, it returns tick marks suitable for a log-scale axis.

func (LogTicks) Ticks

func (t LogTicks) Ticks(mn, mx float64, nticks int) []Tick

Ticks returns Ticks in a specified range

type Normalizer

type Normalizer interface {
	// Normalize transforms a value x in the data coordinate system to
	// the normalized coordinate system.
	Normalize(min, max, x float64) float64
}

Normalizer rescales values from the data coordinate system to the normalized coordinate system.

type PanZoom

type PanZoom struct {

	// XOffset adds offset to X range (pan).
	XOffset float64

	// XScale multiplies X range (zoom).
	XScale float64

	// YOffset adds offset to Y range (pan).
	YOffset float64

	// YScale multiplies Y range (zoom).
	YScale float64
}

PanZoom provides post-styling pan and zoom range manipulation.

func (*PanZoom) Defaults

func (pz *PanZoom) Defaults()

type Plot

type Plot struct {
	// Title of the plot
	Title Text

	// Style has the styling properties for the plot.
	// All end-user configuration should be put in here,
	// rather than modifying other fields directly on the plot.
	Style PlotStyle

	// standard text style with default options
	StandardTextStyle text.Style

	// X, Y, YR, and Z are the horizontal, vertical, right vertical, and depth axes
	// of the plot respectively. These are the actual compiled
	// state data and should not be used for styling: use Style.
	X, Y, YR, Z Axis

	// Legend is the plot's legend.
	Legend Legend

	// Plotters are drawn by calling their Plot method after the axes are drawn.
	Plotters []Plotter

	// PanZoom provides post-styling pan and zoom range factors.
	PanZoom PanZoom

	// HighlightPlotter is the Plotter to highlight. Used for mouse hovering for example.
	// It is the responsibility of the Plotter Plot function to implement highlighting.
	HighlightPlotter Plotter

	// HighlightIndex is the index of the data point to highlight, for HighlightPlotter.
	HighlightIndex int

	// TextShaper for shaping text. Can set to a shared external one,
	// or else the shared plotShaper is used under a mutex lock during Render.
	TextShaper shaped.Shaper

	// PaintBox is the bounding box for the plot within the Paint.
	// For standalone, it is the size of the image.
	PaintBox image.Rectangle

	// Current local plot bounding box in image coordinates, for computing
	// plotting coordinates.
	PlotBox math32.Box2

	// Painter is the current painter being used,
	// which is only valid during rendering, and is set by Draw function.
	// It needs to be exported for different plot types in other packages.
	Painter *paint.Painter
	// contains filtered or unexported fields
}

Plot is the basic type representing a plot. It renders into its own image.RGBA Pixels image, and can also save a corresponding SVG version.

func New

func New() *Plot

New returns a new plot with some reasonable default settings.

func NewTablePlot

func NewTablePlot(dt *table.Table) (*Plot, error)

NewTablePlot returns a new Plot with all configuration based on given table.Table set of columns and associated metadata, which must have Stylers functions set (e.g., [SetStylersTo]) that at least set basic table parameters, including:

  • On: Set the main (typically Role = Y) column On to include in plot.
  • Role: Set the appropriate Roles role for this column (Y, X, etc).
  • Group: Multiple columns used for a given Plotter type must be grouped together with a common name (typically the name of the main Y axis), e.g., for Low, High error bars, Size, Color, etc. If only one On column, then Group can be empty and all other such columns will be grouped.
  • Plotter: Determines the type of Plotter element to use, which in turn determines the additional Roles that can be used within a Group.

Returns nil if no valid plot elements were present.

func (*Plot) Add

func (pt *Plot) Add(ps ...Plotter)

Add adds Plotter element(s) to the plot. When drawing the plot, Plotters are drawn in the order in which they were added to the plot.

func (*Plot) ClosestDataToPixel

func (pt *Plot) ClosestDataToPixel(px, py int) (plt Plotter, plotterIndex, pointIndex int, dist float32, pixel math32.Vector2, data Data, legend string)

ClosestDataToPixel returns the Plotter data point closest to given pixel point, in the Pixels image.

func (*Plot) CurBounds added in v0.1.1

func (pt *Plot) CurBounds() image.Rectangle

CurBounds returns the current render bounds from Paint

func (*Plot) Defaults

func (pt *Plot) Defaults()

Defaults sets defaults

func (*Plot) Draw

func (pt *Plot) Draw(pc *paint.Painter) *paint.Painter

Draw draws the plot to a core paint.Painter, which then can be used with a core render.Renderer to generate an image or SVG document, etc. If painter is nil, then one is created. See Plot.RenderImage and Plot.RenderSVG for convenience methods. Plotters are drawn in the order in which they were added to the plot.

func (*Plot) HideAxes

func (pt *Plot) HideAxes()

HideAxes hides the X and Y axes.

func (*Plot) HideX

func (pt *Plot) HideX()

HideX configures the X axis so that it will not be drawn.

func (*Plot) HideY

func (pt *Plot) HideY()

HideY configures the Y axis so that it will not be drawn.

func (*Plot) HideYR added in v0.1.1

func (pt *Plot) HideYR()

HideYR configures the YR axis so that it will not be drawn.

func (*Plot) NominalX

func (pt *Plot) NominalX(names ...string)

NominalX configures the plot to have a nominal X axis—an X axis with names instead of numbers. The X location corresponding to each name are the integers, e.g., the x value 0 is centered above the first name and 1 is above the second name, etc. Labels for x values that do not end up in range of the X axis will not have tick marks.

func (*Plot) NominalY

func (pt *Plot) NominalY(names ...string)

NominalY is like NominalX, but for the Y axis.

func (*Plot) PX

func (pt *Plot) PX(v float64) float32

PX returns the X-axis plotting coordinate for given raw data value using the current plot bounding region

func (*Plot) PY

func (pt *Plot) PY(v float64) float32

PY returns the Y-axis plotting coordinate for given raw data value

func (*Plot) PYR added in v0.1.1

func (pt *Plot) PYR(v float64) float32

PYR returns the Y-axis plotting coordinate for given raw data value

func (*Plot) PushBounds added in v0.1.1

func (pt *Plot) PushBounds(tb image.Rectangle)

PushBounds returns the current render bounds from Paint

func (*Plot) RenderImage added in v0.1.1

func (pt *Plot) RenderImage() image.Image

RenderImage renders the plot to an image and returns it.

func (*Plot) RenderSVG added in v0.1.1

func (pt *Plot) RenderSVG() []byte

RenderSVG renders the plot to an SVG document and returns it.

func (*Plot) SaveImage

func (pt *Plot) SaveImage(fname string) error

SaveImage renders the plot to an image and saves it to given filename, using the filename extension to determine the file type.

func (*Plot) SaveSVG added in v0.1.1

func (pt *Plot) SaveSVG(fname string) error

SaveSVG renders the plot to an SVG document and saves it to given filename.

func (*Plot) SetSize added in v0.1.1

func (pt *Plot) SetSize(sz image.Point)

SetSize sets the size of the plot, typically in terms of actual device pixels (dots).

func (*Plot) UnitContext added in v0.1.1

func (pt *Plot) UnitContext() *units.Context

UnitContext returns the units.Context to use for styling. This includes the scaling factor.

func (*Plot) UpdateRange

func (pt *Plot) UpdateRange()

UpdateRange updates the axis range values based on current Plot values. This first resets the range so any fixed additional range values should be set after this point.

type PlotStyle

type PlotStyle struct {

	// Title is the overall title of the plot.
	Title string

	// TitleStyle is the text styling parameters for the title.
	TitleStyle TextStyle

	// Background is the background of the plot.
	// The default is [colors.Scheme.Surface].
	Background image.Image

	// Scale multiplies the plot DPI value, to change the overall scale
	// of the rendered plot.  Larger numbers produce larger scaling.
	// Typically use larger numbers when generating plots for inclusion in
	// documents or other cases where the overall plot size will be small.
	Scale float32 `default:"1,2"`

	// Legend has the styling properties for the Legend.
	Legend LegendStyle `display:"add-fields"`

	// Axis has the styling properties for the Axis associated with this Data.
	Axis AxisStyle `display:"add-fields"`

	// XAxis has plot-level properties specific to the XAxis.
	XAxis XAxisStyle `display:"add-fields"`

	// YAxisLabel is the optional label to use for the YAxis instead of the default.
	YAxisLabel string

	// LinesOn determines whether lines are plotted by default at the overall,
	// Plot level, for elements that plot lines (e.g., plots.XY).
	LinesOn DefaultOffOn

	// LineWidth sets the default line width for data plotting lines at the
	// overall Plot level.
	LineWidth units.Value

	// PointsOn determines whether points are plotted by default at the
	// overall Plot level, for elements that plot points (e.g., plots.XY).
	PointsOn DefaultOffOn

	// PointSize sets the default point size at the overall Plot level.
	PointSize units.Value

	// LabelSize sets the default label text size at the overall Plot level.
	LabelSize units.Value

	// BarWidth for Bar plot sets the default width of the bars,
	// which should be less than the Stride (1 typically) to prevent
	// bar overlap. Defaults to .8.
	BarWidth float64

	// ShowErrors can be set to have Plot configuration errors reported.
	// This is particularly important for table-driven plots (e.g., [plotcore.Editor]),
	// but it is not on by default because often there are transitional states
	// with known errors that can lead to false alarms.
	ShowErrors bool
}

PlotStyle has overall plot level styling properties. Some properties provide defaults for individual elements, which can then be overwritten by element-level properties.

func (*PlotStyle) Defaults

func (ps *PlotStyle) Defaults()

func (*PlotStyle) SetAxis

func (t *PlotStyle) SetAxis(v AxisStyle) *PlotStyle

SetAxis sets the [PlotStyle.Axis]: Axis has the styling properties for the Axis associated with this Data.

func (*PlotStyle) SetBackground

func (t *PlotStyle) SetBackground(v image.Image) *PlotStyle

SetBackground sets the [PlotStyle.Background]: Background is the background of the plot. The default is colors.Scheme.Surface.

func (*PlotStyle) SetBarWidth

func (t *PlotStyle) SetBarWidth(v float64) *PlotStyle

SetBarWidth sets the [PlotStyle.BarWidth]: BarWidth for Bar plot sets the default width of the bars, which should be less than the Stride (1 typically) to prevent bar overlap. Defaults to .8.

func (*PlotStyle) SetElementStyle

func (ps *PlotStyle) SetElementStyle(es *Style)

SetElementStyle sets the properties for given element's style based on the global default settings in this PlotStyle.

func (*PlotStyle) SetLabelSize

func (t *PlotStyle) SetLabelSize(v units.Value) *PlotStyle

SetLabelSize sets the [PlotStyle.LabelSize]: LabelSize sets the default label text size at the overall Plot level.

func (*PlotStyle) SetLegend

func (t *PlotStyle) SetLegend(v LegendStyle) *PlotStyle

SetLegend sets the [PlotStyle.Legend]: Legend has the styling properties for the Legend.

func (*PlotStyle) SetLineWidth

func (t *PlotStyle) SetLineWidth(v units.Value) *PlotStyle

SetLineWidth sets the [PlotStyle.LineWidth]: LineWidth sets the default line width for data plotting lines at the overall Plot level.

func (*PlotStyle) SetLinesOn

func (t *PlotStyle) SetLinesOn(v DefaultOffOn) *PlotStyle

SetLinesOn sets the [PlotStyle.LinesOn]: LinesOn determines whether lines are plotted by default at the overall, Plot level, for elements that plot lines (e.g., plots.XY).

func (*PlotStyle) SetPointSize

func (t *PlotStyle) SetPointSize(v units.Value) *PlotStyle

SetPointSize sets the [PlotStyle.PointSize]: PointSize sets the default point size at the overall Plot level.

func (*PlotStyle) SetPointsOn

func (t *PlotStyle) SetPointsOn(v DefaultOffOn) *PlotStyle

SetPointsOn sets the [PlotStyle.PointsOn]: PointsOn determines whether points are plotted by default at the overall Plot level, for elements that plot points (e.g., plots.XY).

func (*PlotStyle) SetScale

func (t *PlotStyle) SetScale(v float32) *PlotStyle

SetScale sets the [PlotStyle.Scale]: Scale multiplies the plot DPI value, to change the overall scale of the rendered plot. Larger numbers produce larger scaling. Typically use larger numbers when generating plots for inclusion in documents or other cases where the overall plot size will be small.

func (*PlotStyle) SetShowErrors added in v0.1.1

func (t *PlotStyle) SetShowErrors(v bool) *PlotStyle

SetShowErrors sets the [PlotStyle.ShowErrors]: ShowErrors can be set to have Plot configuration errors reported. This is particularly important for table-driven plots (e.g., [plotcore.Editor]), but it is not on by default because often there are transitional states with known errors that can lead to false alarms.

func (*PlotStyle) SetTitle

func (t *PlotStyle) SetTitle(v string) *PlotStyle

SetTitle sets the [PlotStyle.Title]: Title is the overall title of the plot.

func (*PlotStyle) SetTitleStyle

func (t *PlotStyle) SetTitleStyle(v TextStyle) *PlotStyle

SetTitleStyle sets the [PlotStyle.TitleStyle]: TitleStyle is the text styling parameters for the title.

func (*PlotStyle) SetXAxis

func (t *PlotStyle) SetXAxis(v XAxisStyle) *PlotStyle

SetXAxis sets the [PlotStyle.XAxis]: XAxis has plot-level properties specific to the XAxis.

func (*PlotStyle) SetYAxisLabel

func (t *PlotStyle) SetYAxisLabel(v string) *PlotStyle

SetYAxisLabel sets the [PlotStyle.YAxisLabel]: YAxisLabel is the optional label to use for the YAxis instead of the default.

type Plotter

type Plotter interface {

	// Plot draws the data to the Plot Paint.
	Plot(pt *Plot)

	// UpdateRange updates the given ranges.
	UpdateRange(plt *Plot, x, y, yr, z *minmax.F64)

	// Data returns the data by roles for this plot, for both the original
	// data and the pixel-transformed X,Y coordinates for that data.
	// This allows a GUI interface to inspect data etc.
	Data() (data Data, pixX, pixY []float32)

	// Stylers returns the styler functions for this element.
	Stylers() *Stylers

	// ApplyStyle applies any stylers to this element,
	// first initializing from the given global plot style, which has
	// already been styled with defaults and all the plot element stylers.
	ApplyStyle(plotStyle *PlotStyle, idx int)
}

Plotter is an interface that wraps the Plot method. Standard implementations of Plotter are in the [plots] package.

func NewPlotter

func NewPlotter(plt *Plot, typeName string, data Data) Plotter

NewPlotter returns a new plotter of given type, e.g., "XY", "Bar" etc, for given data roles (which must include Required roles, and may include Optional ones). Logs an error and returns nil if type name is not a registered type.

type PlotterName

type PlotterName string

PlotterName is the name of a specific plotter type.

type PlotterType

type PlotterType struct {
	// Name of the plot type.
	Name string

	// Doc is the documentation for this Plotter.
	Doc string

	// Required Data roles for this plot. Data for these Roles must be provided.
	Required []Roles

	// Optional Data roles for this plot.
	Optional []Roles

	// New returns a new plotter of this type with given data in given roles.
	New func(plt *Plot, data Data) Plotter
}

PlotterType registers a Plotter so that it can be created with appropriate data.

func PlotterByType

func PlotterByType(typeName string) (*PlotterType, error)

PlotterByType returns PlotterType info for a registered Plotter of given type name, e.g., "XY", "Bar" etc, Returns an error and nil if type name is not a registered type.

type PointStyle

type PointStyle struct {
	// On indicates whether to plot points.
	On DefaultOffOn

	// Shape to draw.
	Shape Shapes

	// Color is the stroke color image specification.
	// Setting to nil turns line off.
	Color image.Image

	// Fill is the color to fill solid regions, in a plot-specific
	// way (e.g., the area below a Line plot, the bar color).
	// Use nil to disable filling.
	Fill image.Image

	// Width is the line width for point glyphs, with a default of 1 Pt (point).
	// Setting to 0 turns line off.
	Width units.Value

	// Size of shape to draw for each point.
	// Defaults to 3 Pt (point).
	Size units.Value
}

PointStyle has style properties for drawing points as different shapes.

func (*PointStyle) Defaults

func (ps *PointStyle) Defaults()

func (*PointStyle) DrawShape

func (ps *PointStyle) DrawShape(pc *paint.Painter, pos math32.Vector2)

DrawShape draws the given shape

func (*PointStyle) IsOn added in v0.1.1

func (ps *PointStyle) IsOn(pt *Plot) bool

IsOn returns true if points are to be drawn. Also computes the dots sizes at this point.

func (*PointStyle) SetColor

func (t *PointStyle) SetColor(v image.Image) *PointStyle

SetColor sets the [PointStyle.Color]: Color is the stroke color image specification. Setting to nil turns line off.

func (*PointStyle) SetFill

func (t *PointStyle) SetFill(v image.Image) *PointStyle

SetFill sets the [PointStyle.Fill]: Fill is the color to fill solid regions, in a plot-specific way (e.g., the area below a Line plot, the bar color). Use nil to disable filling.

func (*PointStyle) SetOn

func (t *PointStyle) SetOn(v DefaultOffOn) *PointStyle

SetOn sets the [PointStyle.On]: On indicates whether to plot points.

func (*PointStyle) SetShape

func (t *PointStyle) SetShape(v Shapes) *PointStyle

SetShape sets the [PointStyle.Shape]: Shape to draw.

func (*PointStyle) SetSize

func (t *PointStyle) SetSize(v units.Value) *PointStyle

SetSize sets the [PointStyle.Size]: Size of shape to draw for each point. Defaults to 3 Pt (point).

func (*PointStyle) SetStroke

func (ps *PointStyle) SetStroke(pt *Plot) bool

SetStroke sets the stroke style in plot paint to current line style. returns false if either the Width = 0 or Color is nil

func (*PointStyle) SetWidth

func (t *PointStyle) SetWidth(v units.Value) *PointStyle

SetWidth sets the [PointStyle.Width]: Width is the line width for point glyphs, with a default of 1 Pt (point). Setting to 0 turns line off.

func (*PointStyle) SpacedColor

func (ps *PointStyle) SpacedColor(idx int)

SpacedColor sets the Color to a default spaced color based on index, if it still has the initial OnSurface default.

type Roles

type Roles int32 //enums:enum

Roles are the roles that a given set of data values can play, designed to be sufficiently generalizable across all different types of plots, even if sometimes it is a bit of a stretch.

const (
	// NoRole is the default no-role specified case.
	NoRole Roles = iota

	// X axis
	X

	// Y axis
	Y

	// Z axis
	Z

	// U is the X component of a vector or first quartile in Box plot, etc.
	U

	// V is the Y component of a vector or third quartile in a Box plot, etc.
	V

	// W is the Z component of a vector
	W

	// Low is a lower error bar or region.
	Low

	// High is an upper error bar or region.
	High

	// Size controls the size of points etc.
	Size

	// Color controls the color of points or other elements.
	Color

	// Label renders a label, typically from string data,
	// but can also be used for values.
	Label

	// Split is a special role for table-based plots. The
	// unique values of this data are used to split the other
	// plot data into groups, with each group added to the legend.
	// A different default color will be used for each such group.
	Split
)
const RolesN Roles = 13

RolesN is the highest valid value for type Roles, plus one.

func RolesValues

func RolesValues() []Roles

RolesValues returns all possible values for the type Roles.

func (Roles) Desc

func (i Roles) Desc() string

Desc returns the description of the Roles value.

func (Roles) Int64

func (i Roles) Int64() int64

Int64 returns the Roles value as an int64.

func (Roles) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*Roles) SetInt64

func (i *Roles) SetInt64(in int64)

SetInt64 sets the Roles value from an int64.

func (*Roles) SetString

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

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

func (Roles) String

func (i Roles) String() string

String returns the string representation of this Roles value.

func (*Roles) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Roles) Values

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

Values returns all possible values for the type Roles.

type Shapes

type Shapes int32 //enums:enum

Shapes has the options for how to draw points in the plot.

const (
	// Circle is a solid circle
	Circle Shapes = iota

	// Box is a filled square
	Box

	// Pyramid is a filled triangle
	Pyramid

	// Plus is a plus sign
	Plus

	// Cross is a big X
	Cross

	// Ring is the outline of a circle
	Ring

	// Square is the outline of a square
	Square

	// Triangle is the outline of a triangle
	Triangle
)
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 Style

type Style struct {

	// Plot has overall plot-level properties, which can be set by any
	// plot element, and are updated first, before applying element-wise styles.
	Plot PlotStyle `display:"-"`

	// On specifies whether to plot this item, for table-based plots.
	On bool

	// Plotter is the type of plotter to use in plotting this data,
	// for [plot.NewTablePlot] [table.Table] driven plots.
	// Blank means use default ([plots.XY] is overall default).
	Plotter PlotterName

	// Role specifies how a particular column of data should be used,
	// for [plot.NewTablePlot] [table.Table] driven plots.
	Role Roles

	// Group specifies a group of related data items,
	// for [plot.NewTablePlot] [table.Table] driven plots,
	// where different columns of data within the same Group play different Roles.
	Group string

	// Range is the effective range of data to plot, where either end can be fixed.
	Range minmax.Range64 `display:"inline"`

	// Label provides an alternative label to use for axis, if set.
	Label string

	// NoLegend excludes this item from the legend when it otherwise would be included,
	// for [plot.NewTablePlot] [table.Table] driven plots.
	// Role = Y values are included in the Legend by default.
	NoLegend bool

	// RightY specifies that this should use the right-side alternate Y axis.
	RightY bool

	// NTicks sets the desired number of ticks for the axis, if > 0.
	NTicks int

	// LabelSkip is the number of data points to skip between Labels.
	// 0 means plot the Label at every point.
	LabelSkip int

	// Line has style properties for drawing lines.
	Line LineStyle `display:"add-fields"`

	// Point has style properties for drawing points.
	Point PointStyle `display:"add-fields"`

	// Text has style properties for rendering text.
	Text TextStyle `display:"add-fields"`

	// Width has various plot width properties.
	Width WidthStyle `display:"inline"`
}

Style contains the plot styling properties relevant across most plot types. These properties apply to individual plot elements while the Plot properties applies to the overall plot itself.

func NewStyle

func NewStyle() *Style

NewStyle returns a new Style object with defaults applied.

func (*Style) Defaults

func (st *Style) Defaults()

func (*Style) SetGroup

func (t *Style) SetGroup(v string) *Style

SetGroup sets the [Style.Group]: Group specifies a group of related data items, for plot.NewTablePlot table.Table driven plots, where different columns of data within the same Group play different Roles.

func (*Style) SetLabel

func (t *Style) SetLabel(v string) *Style

SetLabel sets the [Style.Label]: Label provides an alternative label to use for axis, if set.

func (*Style) SetLabelSkip

func (t *Style) SetLabelSkip(v int) *Style

SetLabelSkip sets the [Style.LabelSkip]: LabelSkip is the number of data points to skip between Labels. 0 means plot the Label at every point.

func (*Style) SetLine

func (t *Style) SetLine(v LineStyle) *Style

SetLine sets the [Style.Line]: Line has style properties for drawing lines.

func (*Style) SetNTicks

func (t *Style) SetNTicks(v int) *Style

SetNTicks sets the [Style.NTicks]: NTicks sets the desired number of ticks for the axis, if > 0.

func (*Style) SetNoLegend

func (t *Style) SetNoLegend(v bool) *Style

SetNoLegend sets the [Style.NoLegend]: NoLegend excludes this item from the legend when it otherwise would be included, for plot.NewTablePlot table.Table driven plots. Role = Y values are included in the Legend by default.

func (*Style) SetOn

func (t *Style) SetOn(v bool) *Style

SetOn sets the [Style.On]: On specifies whether to plot this item, for table-based plots.

func (*Style) SetPlot

func (t *Style) SetPlot(v PlotStyle) *Style

SetPlot sets the [Style.Plot]: Plot has overall plot-level properties, which can be set by any plot element, and are updated first, before applying element-wise styles.

func (*Style) SetPlotter

func (t *Style) SetPlotter(v PlotterName) *Style

SetPlotter sets the [Style.Plotter]: Plotter is the type of plotter to use in plotting this data, for plot.NewTablePlot table.Table driven plots. Blank means use default ([plots.XY] is overall default).

func (*Style) SetPoint

func (t *Style) SetPoint(v PointStyle) *Style

SetPoint sets the [Style.Point]: Point has style properties for drawing points.

func (*Style) SetRange

func (t *Style) SetRange(v minmax.Range64) *Style

SetRange sets the [Style.Range]: Range is the effective range of data to plot, where either end can be fixed.

func (*Style) SetRightY added in v0.1.1

func (t *Style) SetRightY(v bool) *Style

SetRightY sets the [Style.RightY]: RightY specifies that this should use the right-side alternate Y axis.

func (*Style) SetRole

func (t *Style) SetRole(v Roles) *Style

SetRole sets the [Style.Role]: Role specifies how a particular column of data should be used, for plot.NewTablePlot table.Table driven plots.

func (*Style) SetText

func (t *Style) SetText(v TextStyle) *Style

SetText sets the [Style.Text]: Text has style properties for rendering text.

func (*Style) SetWidth

func (t *Style) SetWidth(v WidthStyle) *Style

SetWidth sets the [Style.Width]: Width has various plot width properties.

type Stylers

type Stylers []func(s *Style)

Stylers is a list of styling functions that set Style properties. These are called in the order added.

func GetStylers

func GetStylers(obj any) Stylers

GetStylers returns Stylers functions from given object's metadata. Returns nil if none or no metadata.

func GetStylersFromData

func GetStylersFromData(data Data, role Roles) Stylers

GetStylersFromData returns Stylers from given role in given Data. nil if not present. Mostly used internally for Plotters implementations.

func (*Stylers) Add

func (st *Stylers) Add(f func(s *Style))

Add Adds a styling function to the list.

func (*Stylers) NewStyle

func (st *Stylers) NewStyle(ps *PlotStyle) *Style

NewStyle returns a new Style object with styling functions applied on top of Style defaults.

func (*Stylers) Run

func (st *Stylers) Run(s *Style)

Run runs the list of styling functions on given Style object.

type Text

type Text struct {

	// text string, which can use HTML formatting
	Text string

	// styling for this text element
	Style TextStyle

	// PaintText is the [shaped.Lines] for painting the text.
	PaintText *shaped.Lines
	// contains filtered or unexported fields
}

Text specifies a single text element in a plot

func (*Text) Config

func (tx *Text) Config(pt *Plot)

config is called during the layout of the plot, prior to drawing

func (*Text) Defaults

func (tx *Text) Defaults()

func (*Text) Draw

func (tx *Text) Draw(pt *Plot, pos math32.Vector2)

Draw renders the text at given upper left position

func (*Text) PosX

func (tx *Text) PosX(width float32) math32.Vector2

PosX returns the starting position for a horizontally-aligned text element, based on given width. Text must have been config'd already.

func (*Text) PosY

func (tx *Text) PosY(height float32) math32.Vector2

PosY returns the starting position for a vertically-rotated text element, based on given height. Text must have been config'd already.

func (*Text) Size added in v0.1.1

func (tx *Text) Size() math32.Vector2

Size returns the actual render size of the text.

func (*Text) ToDots

func (tx *Text) ToDots(uc *units.Context)

type TextStyle

type TextStyle struct {
	// Size of font to render. Default is 16dp
	Size units.Value

	// Family name for font (inherited): ordered list of comma-separated names
	// from more general to more specific to use. Use split on, to parse.
	Family rich.Family

	// Color of text.
	Color image.Image

	// Align specifies how to align text along the relevant
	// dimension for the text element.
	Align styles.Aligns

	// Padding is used in a case-dependent manner to add
	// space around text elements.
	Padding units.Value

	// Rotation of the text, in degrees.
	Rotation float32

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

TextStyle specifies styling parameters for Text elements.

func (*TextStyle) Defaults

func (ts *TextStyle) Defaults()

func (*TextStyle) SetAlign

func (t *TextStyle) SetAlign(v styles.Aligns) *TextStyle

SetAlign sets the [TextStyle.Align]: Align specifies how to align text along the relevant dimension for the text element.

func (*TextStyle) SetColor

func (t *TextStyle) SetColor(v image.Image) *TextStyle

SetColor sets the [TextStyle.Color]: Color of text.

func (*TextStyle) SetFamily

func (t *TextStyle) SetFamily(v rich.Family) *TextStyle

SetFamily sets the [TextStyle.Family]: Family name for font (inherited): ordered list of comma-separated names from more general to more specific to use. Use split on, to parse.

func (*TextStyle) SetOffset

func (t *TextStyle) SetOffset(v units.XY) *TextStyle

SetOffset sets the [TextStyle.Offset]: Offset is added directly to the final label location.

func (*TextStyle) SetPadding

func (t *TextStyle) SetPadding(v units.Value) *TextStyle

SetPadding sets the [TextStyle.Padding]: Padding is used in a case-dependent manner to add space around text elements.

func (*TextStyle) SetRotation

func (t *TextStyle) SetRotation(v float32) *TextStyle

SetRotation sets the [TextStyle.Rotation]: Rotation of the text, in degrees.

func (*TextStyle) SetSize

func (t *TextStyle) SetSize(v units.Value) *TextStyle

SetSize sets the [TextStyle.Size]: Size of font to render. Default is 16dp

type Thumbnailer

type Thumbnailer interface {
	// Thumbnail draws an thumbnail representing a legend entry.
	// The thumbnail will usually show a smaller representation
	// of the style used to plot the corresponding data.
	Thumbnail(pt *Plot)
}

Thumbnailer wraps the Thumbnail method, which draws the small image in a legend representing the style of data.

type Tick

type Tick struct {
	// Value is the data value marked by this Tick.
	Value float64

	// Label is the text to display at the tick mark.
	// If Label is an empty string then this is a minor tick mark.
	Label string
}

A Tick is a single tick mark on an axis.

func (*Tick) IsMinor

func (tk *Tick) IsMinor() bool

IsMinor returns true if this is a minor tick mark.

type Ticker

type Ticker interface {
	// Ticks returns Ticks in a specified range, with desired number of ticks,
	// which can be ignored depending on the ticker type.
	Ticks(mn, mx float64, nticks int) []Tick
}

Ticker creates Ticks in a specified range

type TimeTicks

type TimeTicks struct {
	// Ticker is used to generate a set of ticks.
	// If nil, DefaultTicks will be used.
	Ticker Ticker

	// Format is the textual representation of the time value.
	// If empty, time.RFC3339 will be used
	Format string

	// Time takes a float32 value and converts it into a time.Time.
	// If nil, UTCUnixTime is used.
	Time func(t float64) time.Time
}

TimeTicks is suitable for axes representing time values.

func (TimeTicks) Ticks

func (t TimeTicks) Ticks(mn, mx float64, nticks int) []Tick

Ticks implements plot.Ticker.

type Valuer

type Valuer interface {
	// Len returns the number of values.
	Len() int

	// Float1D(i int) returns float64 value at given index.
	Float1D(i int) float64

	// String1D(i int) returns string value at given index.
	String1D(i int) string
}

Valuer is the data interface for plotting, supporting either float64 or string representations. It is satisfied by the tensor.Tensor interface, so a tensor can be used directly for plot Data.

type Values

type Values []float64

Values provides a minimal implementation of the Data interface using a slice of float64.

func CopyRole

func CopyRole(data Data, role Roles) Values

CopyRole returns Values copy of given role from given data map, returning nil if role not present.

func CopyValues

func CopyValues(data Valuer) (Values, error)

CopyValues returns a Values that is a copy of the values from Data, or an error if there are no values, or if one of the copied values is a Infinity. NaN values are skipped in the copying process.

func MustCopyRole

func MustCopyRole(data Data, role Roles) Values

MustCopyRole returns Values copy of given role from given data map, logging an error and returning nil if not present.

func (Values) Float1D

func (vs Values) Float1D(i int) float64

func (Values) Len

func (vs Values) Len() int

func (Values) String1D

func (vs Values) String1D(i int) string

type WidthStyle

type WidthStyle struct {
	// Cap is the width of the caps drawn at the top of error bars.
	// The default is 10dp
	Cap units.Value

	// Offset for Bar plot is the offset added to each X axis value
	// relative to the Stride computed value (X = offset + index * Stride)
	// Defaults to 0.
	Offset float64

	// Stride for Bar plot is distance between bars. Defaults to 1.
	Stride float64

	// Width for Bar plot is the width of the bars, as a fraction of the Stride,
	// to prevent bar overlap. Defaults to .8.
	Width float64 `min:"0.01" max:"1" default:"0.8"`

	// Pad for Bar plot 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 float64
}

WidthStyle contains various plot width properties relevant across different plot types.

func (*WidthStyle) Defaults

func (ws *WidthStyle) Defaults()

func (*WidthStyle) SetCap

func (t *WidthStyle) SetCap(v units.Value) *WidthStyle

SetCap sets the [WidthStyle.Cap]: Cap is the width of the caps drawn at the top of error bars. The default is 10dp

func (*WidthStyle) SetOffset

func (t *WidthStyle) SetOffset(v float64) *WidthStyle

SetOffset sets the [WidthStyle.Offset]: Offset for Bar plot is the offset added to each X axis value relative to the Stride computed value (X = offset + index * Stride) Defaults to 0.

func (*WidthStyle) SetPad

func (t *WidthStyle) SetPad(v float64) *WidthStyle

SetPad sets the [WidthStyle.Pad]: Pad for Bar plot 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.

func (*WidthStyle) SetStride

func (t *WidthStyle) SetStride(v float64) *WidthStyle

SetStride sets the [WidthStyle.Stride]: Stride for Bar plot is distance between bars. Defaults to 1.

func (*WidthStyle) SetWidth

func (t *WidthStyle) SetWidth(v float64) *WidthStyle

SetWidth sets the [WidthStyle.Width]: Width for Bar plot is the width of the bars, as a fraction of the Stride, to prevent bar overlap. Defaults to .8.

type XAxisStyle

type XAxisStyle struct {

	// Column specifies the column to use for the common X axis,
	// for [plot.NewTablePlot] [table.Table] driven plots.
	// If empty, standard Group-based role binding is used: the last column
	// within the same group with Role=X is used.
	Column string

	// Rotation is the rotation of the X Axis labels, in degrees.
	Rotation float32

	// Label is the optional label to use for the XAxis instead of the default.
	Label string

	// Range is the effective range of XAxis data to plot, where either end can be fixed.
	Range minmax.Range64 `display:"inline"`

	// Scale specifies how values are scaled along the X axis:
	// Linear, Log, Inverted
	Scale AxisScales
}

XAxisStyle has overall plot level styling properties for the XAxis.

func (*XAxisStyle) SetColumn

func (t *XAxisStyle) SetColumn(v string) *XAxisStyle

SetColumn sets the [XAxisStyle.Column]: Column specifies the column to use for the common X axis, for plot.NewTablePlot table.Table driven plots. If empty, standard Group-based role binding is used: the last column within the same group with Role=X is used.

func (*XAxisStyle) SetLabel

func (t *XAxisStyle) SetLabel(v string) *XAxisStyle

SetLabel sets the [XAxisStyle.Label]: Label is the optional label to use for the XAxis instead of the default.

func (*XAxisStyle) SetRange

func (t *XAxisStyle) SetRange(v minmax.Range64) *XAxisStyle

SetRange sets the [XAxisStyle.Range]: Range is the effective range of XAxis data to plot, where either end can be fixed.

func (*XAxisStyle) SetRotation

func (t *XAxisStyle) SetRotation(v float32) *XAxisStyle

SetRotation sets the [XAxisStyle.Rotation]: Rotation is the rotation of the X Axis labels, in degrees.

func (*XAxisStyle) SetScale

func (t *XAxisStyle) SetScale(v AxisScales) *XAxisStyle

SetScale sets the [XAxisStyle.Scale]: Scale specifies how values are scaled along the X axis: Linear, Log, Inverted

Directories

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

Jump to

Keyboard shortcuts

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