eplot

package
v2.0.0-dev0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: BSD-3-Clause Imports: 39 Imported by: 3

README

eplot

Docs: GoDoc

eplot provides an interactive, graphical plotting utility for etable data, as a GoGi Widget, with multiple Y axis values and options for XY vs. Bar plots.

To use, create a Plot2D widget in a GoGi scenegraph, e.g.:

		plt := gui.TabView.AddNewTab(eplot.KiT_Plot2D, mode+" "+time+" Plot").(*eplot.Plot2D)
		plt.SetTable(lt.Table)
		plt.Params.FmMetaMap(lt.Meta)

Documentation

Overview

Package eplot provides an interactive, graphical plotting utility for etable data.

It also provides various utilities to simplify the plotting of data from etable.Table data tables, using the gonum/plot package.

Index

Constants

View Source
const (
	On       bool = true
	Off           = false
	FixMin        = true
	FloatMin      = false
	FixMax        = true
	FloatMax      = false
)

use these for SetColParams args

View Source
const PlotColsHeaderN = 2

Variables

View Source
var Plot2DType = gti.AddType(&gti.Type{
	Name:      "goki.dev/etable/v2/eplot.Plot2D",
	ShortName: "eplot.Plot2D",
	IDName:    "plot-2-d",
	Doc:       "Plot2D is a GoGi Widget that provides a 2D plot of selected columns of etable data",
	Directives: gti.Directives{
		&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
	},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Table", &gti.Field{Name: "Table", Type: "*goki.dev/etable/v2/etable.IdxView", LocalType: "*etable.IdxView", Doc: "the idxview of the table that we're plotting", Directives: gti.Directives{}, Tag: "set:\"-\""}},
		{"Params", &gti.Field{Name: "Params", Type: "goki.dev/etable/v2/eplot.PlotParams", LocalType: "PlotParams", Doc: "the overall plot parameters", Directives: gti.Directives{}, Tag: ""}},
		{"Cols", &gti.Field{Name: "Cols", Type: "[]*goki.dev/etable/v2/eplot.ColParams", LocalType: "[]*ColParams", Doc: "the parameters for each column of the table", Directives: gti.Directives{}, Tag: "set:\"-\""}},
		{"Plot", &gti.Field{Name: "Plot", Type: "*gonum.org/v1/plot.Plot", LocalType: "*plot.Plot", Doc: "the gonum plot that actually does the plotting -- always save the last one generated", Directives: gti.Directives{}, Tag: "set:\"-\" edit:\"-\" json:\"-\" xml:\"-\""}},
		{"ConfigPlotFunc", &gti.Field{Name: "ConfigPlotFunc", Type: "func()", LocalType: "func()", Doc: "ConfigPlotFunc is a function to call to configure [Plot2D.Plot], the gonum plot that\nactually does the plotting. It is called after [Plot] is generated, and properties\nof [Plot] can be modified in it. Properties of [Plot] should not be modified outside\nof this function, as doing so will have no effect.", Directives: gti.Directives{}, Tag: "json:\"-\" xml:\"-\""}},
		{"SVGFile", &gti.Field{Name: "SVGFile", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "current svg file", Directives: gti.Directives{}, Tag: ""}},
		{"DataFile", &gti.Field{Name: "DataFile", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "current csv data file", Directives: gti.Directives{}, Tag: ""}},
		{"InPlot", &gti.Field{Name: "InPlot", Type: "bool", LocalType: "bool", Doc: "currently doing a plot", Directives: gti.Directives{}, Tag: "set:\"-\" edit:\"-\" json:\"-\" xml:\"-\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Layout", &gti.Field{Name: "Layout", Type: "goki.dev/gi/v2/gi.Layout", LocalType: "gi.Layout", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods: ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{
		{"SaveSVG", &gti.Method{Name: "SaveSVG", Doc: "SaveSVG saves the plot to an svg -- first updates to ensure that plot is current", Directives: gti.Directives{
			&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
		}, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
			{"fname", &gti.Field{Name: "fname", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "", Directives: gti.Directives{}, Tag: ""}},
		}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}},
		{"SavePNG", &gti.Method{Name: "SavePNG", Doc: "SavePNG saves the current plot to a png, capturing current render", Directives: gti.Directives{
			&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
		}, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
			{"fname", &gti.Field{Name: "fname", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "", Directives: gti.Directives{}, Tag: ""}},
		}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}},
		{"SaveCSV", &gti.Method{Name: "SaveCSV", Doc: "SaveCSV saves the Table data to a csv (comma-separated values) file with headers (any delim)", Directives: gti.Directives{
			&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
		}, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
			{"fname", &gti.Field{Name: "fname", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "", Directives: gti.Directives{}, Tag: ""}},
			{"delim", &gti.Field{Name: "delim", Type: "goki.dev/etable/v2/etable.Delims", LocalType: "etable.Delims", Doc: "", Directives: gti.Directives{}, Tag: ""}},
		}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}},
		{"SaveAll", &gti.Method{Name: "SaveAll", Doc: "SaveAll saves the current plot to a png, svg, and the data to a tsv -- full save\nAny extension is removed and appropriate extensions are added", Directives: gti.Directives{
			&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
		}, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
			{"fname", &gti.Field{Name: "fname", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "", Directives: gti.Directives{}, Tag: ""}},
		}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}},
		{"OpenCSV", &gti.Method{Name: "OpenCSV", Doc: "OpenCSV opens the Table data from a csv (comma-separated values) file (or any delim)", Directives: gti.Directives{
			&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
		}, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
			{"fname", &gti.Field{Name: "fname", Type: "goki.dev/gi/v2/gi.FileName", LocalType: "gi.FileName", Doc: "", Directives: gti.Directives{}, Tag: ""}},
			{"delim", &gti.Field{Name: "delim", Type: "goki.dev/etable/v2/etable.Delims", LocalType: "etable.Delims", Doc: "", Directives: gti.Directives{}, Tag: ""}},
		}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}},
		{"SetColsByName", &gti.Method{Name: "SetColsByName", Doc: "SetColsByName turns cols On or Off if their name contains given string", Directives: gti.Directives{
			&gti.Directive{Tool: "gti", Directive: "add", Args: []string{}},
		}, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
			{"nameContains", &gti.Field{Name: "nameContains", Type: "string", LocalType: "string", Doc: "", Directives: gti.Directives{}, Tag: ""}},
			{"on", &gti.Field{Name: "on", Type: "bool", LocalType: "bool", Doc: "", Directives: gti.Directives{}, Tag: ""}},
		}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}},
	}),
	Instance: &Plot2D{},
})

Plot2DType is the gti.Type for Plot2D

ShapeGlyphs contains the draw.GlyphDrawer for each of the Shapes.

Functions

func MetaMapLower

func MetaMapLower(meta map[string]string, key string) (string, bool)

MetaMapLower tries meta data access by lower-case version of key too

func PlotViewSVG

func PlotViewSVG(plt *plot.Plot, svge *gi.SVG, scale float64)

PlotViewSVG shows the given gonum Plot in given GoGi svg editor widget. The scale rescales the default font sizes -- 2-4 recommended. This call must generally be enclosed within an UpdateStart / End as part of the overall update routine using it. if called from a different goroutine, it is essential to surround with BlockUpdates on Viewport as this does full damage to the tree.

func SaveSVGView

func SaveSVGView(fname string, plt *plot.Plot, svge *gi.SVG, scale float64) error

SaveSVGView saves the given gonum Plot exactly as it is rendered given GoGi svg editor widget. The scale rescales the default font sizes -- 2-4 recommended.

func StringViewSVG

func StringViewSVG(svgstr string, svge *gi.SVG, scale float64)

StringViewSVG shows the given svg string in given GoGi svg editor widget Scale to fit your window -- e.g., 2-3 depending on sizes

Types

type ColParams

type ColParams struct {

	// whether to plot this column
	On bool

	// name of column we're plotting
	Col string `label:"Column"`

	// whether to plot lines; uses the overall plot option if unset
	Lines option.Option[bool]

	// whether to plot points with symbols; uses the overall plot option if unset
	Points option.Option[bool]

	// the width of lines; uses the overall plot option if unset
	LineWidth option.Option[float64]

	// the size of points; uses the overall plot option if unset
	PointSize option.Option[float64]

	// the shape used to draw points; uses the overall plot option if unset
	PointShape option.Option[Shapes]

	// effective range of data to plot -- either end can be fixed
	Range minmax.Range64

	// full actual range of data -- only valid if specifically computed
	FullRange minmax.F64

	// color to use when plotting the line / column
	Color color.Color

	// desired number of ticks
	NTicks int

	// if non-empty, this is an alternative label to use in plotting
	Lbl string `label:"Label"`

	// if column has n-dimensional tensor cells in each row, this is the index within each cell to plot -- use -1 to plot *all* indexes as separate lines
	TensorIdx int

	// specifies a column containing error bars for this column
	ErrCol string

	// if true this is a string column -- plots as labels
	IsString bool `edit:"-"`

	// our plot, for update method
	Plot *Plot2D `copy:"-" json:"-" xml:"-" view:"-"`
}

ColParams are parameters for plotting one column of data

func (*ColParams) CopyFrom

func (cp *ColParams) CopyFrom(fr *ColParams)

CopyFrom copies from other col params

func (*ColParams) Defaults

func (cp *ColParams) Defaults()

Defaults sets defaults if nil vals present

func (*ColParams) FmMetaMap

func (cp *ColParams) FmMetaMap(meta map[string]string)

FmMetaMap sets plot params from meta data map

func (*ColParams) Label

func (cp *ColParams) Label() string

func (*ColParams) Update

func (cp *ColParams) Update()

Update satisfies the gi.Updater interface and will trigger display update on edits

type ErrBarChart

type ErrBarChart struct {
	// Values are the plotted values
	Values plotter.Values

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

	// Start is starting offset -- first bar is centered at this point.
	// Defaults to 1.
	Start float64

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

	// Width is the width of the bars in source data units.  Defaults to .8
	Width float64

	// Pad is additional space at start / end of data range, to keep bars from
	// overflowing ends.  This amount is subtracted from Start
	// 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.
	Pad float64

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

	// LineStyle is the style of the outline of the bars.
	draw.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

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

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

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

func NewErrBarChart

func NewErrBarChart(vs, ers plotter.Valuer) (*ErrBarChart, error)

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

func (*ErrBarChart) BarHeight

func (b *ErrBarChart) 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 (*ErrBarChart) DataRange

func (b *ErrBarChart) DataRange() (xmin, xmax, ymin, ymax float64)

DataRange implements the plot.DataRanger interface.

func (*ErrBarChart) Defaults

func (b *ErrBarChart) Defaults()

func (*ErrBarChart) GlyphBoxes

func (b *ErrBarChart) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox

GlyphBoxes implements the GlyphBoxer interface.

func (*ErrBarChart) Plot

func (b *ErrBarChart) Plot(c draw.Canvas, plt *plot.Plot)

Plot implements the plot.Plotter interface.

func (*ErrBarChart) StackOn

func (b *ErrBarChart) StackOn(on *ErrBarChart)

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

func (*ErrBarChart) Thumbnail

func (b *ErrBarChart) Thumbnail(c *draw.Canvas)

Thumbnail fulfills the plot.Thumbnailer interface.

type Plot2D

type Plot2D struct {
	gi.Layout

	// the idxview of the table that we're plotting
	Table *etable.IdxView `set:"-"`

	// the overall plot parameters
	Params PlotParams

	// the parameters for each column of the table
	Cols []*ColParams `set:"-"`

	// the gonum plot that actually does the plotting -- always save the last one generated
	Plot *plot.Plot `set:"-" edit:"-" json:"-" xml:"-"`

	// ConfigPlotFunc is a function to call to configure [Plot2D.Plot], the gonum plot that
	// actually does the plotting. It is called after [Plot] is generated, and properties
	// of [Plot] can be modified in it. Properties of [Plot] should not be modified outside
	// of this function, as doing so will have no effect.
	ConfigPlotFunc func() `json:"-" xml:"-"`

	// current svg file
	SVGFile gi.FileName

	// current csv data file
	DataFile gi.FileName

	// currently doing a plot
	InPlot bool `set:"-" edit:"-" json:"-" xml:"-"`
}

Plot2D is a GoGi Widget that provides a 2D plot of selected columns of etable data

func NewPlot2D

func NewPlot2D(par ki.Ki, name ...string) *Plot2D

NewPlot2D adds a new Plot2D with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func NewSubPlot

func NewSubPlot(par gi.Widget, name ...string) *Plot2D

NewSubPlot returns a Plot2D with its own separate Toolbar, suitable for a tab or other element that is not the main plot.

func (*Plot2D) ColParams

func (pl *Plot2D) ColParams(colNm string) *ColParams

ColParams returns the current column parameters by name (to access by index, just use Cols directly) returns nil if not found

func (*Plot2D) ColParamsTry

func (pl *Plot2D) ColParamsTry(colNm string) (*ColParams, error)

ColParamsTry returns the current column parameters by name (to access by index, just use Cols directly) Try version returns error message if not found.

func (*Plot2D) ColsConfig

func (pl *Plot2D) ColsConfig()

ColsConfig configures the column gui buttons

func (*Plot2D) ColsFmMetaMap

func (pl *Plot2D) ColsFmMetaMap(meta map[string]string)

ColsFmMetaMap updates all the column settings from given meta map

func (*Plot2D) ColsLay

func (pl *Plot2D) ColsLay() *gi.Frame

func (*Plot2D) ColsListUpdate

func (pl *Plot2D) ColsListUpdate()

ColsListUpdate updates the list of columns

func (*Plot2D) ColsUpdate

func (pl *Plot2D) ColsUpdate()

ColsUpdate updates the display toggles for all the cols

func (*Plot2D) ConfigPlot

func (pl *Plot2D) ConfigPlot()

ConfigPlot configures the overall view widget

func (*Plot2D) ConfigToolbar

func (pl *Plot2D) ConfigToolbar(tb *gi.Toolbar)

func (*Plot2D) ConfigWidget

func (pl *Plot2D) ConfigWidget()

func (*Plot2D) CopyFieldsFrom

func (pl *Plot2D) CopyFieldsFrom(frm any)

func (*Plot2D) DeleteCols

func (pl *Plot2D) DeleteCols()

DeleteCols deletes any existing cols, to ensure an update to new table

func (*Plot2D) GenPlot

func (pl *Plot2D) GenPlot()

GenPlot generates the plot and renders it to SVG It surrounds operation with InPlot true / false to prevent multiple updates

func (*Plot2D) GenPlotBar

func (pl *Plot2D) GenPlotBar()

GenPlotBar generates a Bar plot, setting GPlot variable

func (*Plot2D) GenPlotXY

func (pl *Plot2D) GenPlotXY()

GenPlotXY generates an XY (lines, points) plot, setting GPlot variable

func (*Plot2D) GoUpdatePlot

func (pl *Plot2D) GoUpdatePlot()

GoUpdatePlot updates the display based on current IdxView into table. this version can be called from go routines.

func (*Plot2D) KiType

func (t *Plot2D) KiType() *gti.Type

KiType returns the *gti.Type of Plot2D

func (*Plot2D) New

func (t *Plot2D) New() ki.Ki

New returns a new *Plot2D value

func (*Plot2D) OnAdd

func (pl *Plot2D) OnAdd()

func (*Plot2D) OnInit

func (pl *Plot2D) OnInit()

func (*Plot2D) OpenCSV

func (pl *Plot2D) OpenCSV(fname gi.FileName, delim etable.Delims)

OpenCSV opens the Table data from a csv (comma-separated values) file (or any delim)

func (*Plot2D) PlotConfig

func (pl *Plot2D) PlotConfig()

PlotConfig configures the PlotView

func (*Plot2D) PlotXAxis

func (pl *Plot2D) PlotXAxis(plt *plot.Plot, ixvw *etable.IdxView) (xi int, xview *etable.IdxView, xbreaks []int, err error)

PlotXAxis processes the XAxis and returns its index and any breaks to insert based on negative X axis traversals or NaN values. xbreaks always ends in last row.

func (*Plot2D) SVGPlot

func (pl *Plot2D) SVGPlot() *gi.SVG

func (*Plot2D) SaveAll

func (pl *Plot2D) SaveAll(fname gi.FileName)

SaveAll saves the current plot to a png, svg, and the data to a tsv -- full save Any extension is removed and appropriate extensions are added

func (*Plot2D) SaveCSV

func (pl *Plot2D) SaveCSV(fname gi.FileName, delim etable.Delims)

SaveCSV saves the Table data to a csv (comma-separated values) file with headers (any delim)

func (*Plot2D) SavePNG

func (pl *Plot2D) SavePNG(fname gi.FileName)

SavePNG saves the current plot to a png, capturing current render

func (*Plot2D) SaveSVG

func (pl *Plot2D) SaveSVG(fname gi.FileName)

SaveSVG saves the plot to an svg -- first updates to ensure that plot is current

func (*Plot2D) SetAllCols

func (pl *Plot2D) SetAllCols(on bool)

SetAllCols turns all Cols on or off (except X axis)

func (*Plot2D) SetClass

func (t *Plot2D) SetClass(v string) *Plot2D

SetClass sets the [Plot2D.Class]

func (*Plot2D) SetColParams

func (pl *Plot2D) SetColParams(colNm string, on bool, fixMin bool, min float64, fixMax bool, max float64) *ColParams

SetColParams sets main parameters for one column

func (*Plot2D) SetColsByName

func (pl *Plot2D) SetColsByName(nameContains string, on bool)

SetColsByName turns cols On or Off if their name contains given string

func (*Plot2D) SetConfigPlotFunc

func (t *Plot2D) SetConfigPlotFunc(v func()) *Plot2D

SetConfigPlotFunc sets the [Plot2D.ConfigPlotFunc]: ConfigPlotFunc is a function to call to configure [Plot2D.Plot], the gonum plot that actually does the plotting. It is called after [Plot] is generated, and properties of [Plot] can be modified in it. Properties of [Plot] should not be modified outside of this function, as doing so will have no effect.

func (*Plot2D) SetCustomContextMenu

func (t *Plot2D) SetCustomContextMenu(v func(m *gi.Scene)) *Plot2D

SetCustomContextMenu sets the [Plot2D.CustomContextMenu]

func (*Plot2D) SetDataFile

func (t *Plot2D) SetDataFile(v gi.FileName) *Plot2D

SetDataFile sets the [Plot2D.DataFile]: current csv data file

func (*Plot2D) SetParams

func (t *Plot2D) SetParams(v PlotParams) *Plot2D

SetParams sets the [Plot2D.Params]: the overall plot parameters

func (*Plot2D) SetStackTop

func (t *Plot2D) SetStackTop(v int) *Plot2D

SetStackTop sets the [Plot2D.StackTop]

func (*Plot2D) SetSvgfile

func (t *Plot2D) SetSvgfile(v gi.FileName) *Plot2D

SetSvgfile sets the [Plot2D.SVGFile]: current svg file

func (*Plot2D) SetTable

func (pl *Plot2D) SetTable(tab *etable.Table) *Plot2D

SetTable sets the table to view and updates view

func (*Plot2D) SetTableView

func (pl *Plot2D) SetTableView(tab *etable.IdxView) *Plot2D

SetTableView sets the idxview of table to view and updates view

func (*Plot2D) SetTooltip

func (t *Plot2D) SetTooltip(v string) *Plot2D

SetTooltip sets the [Plot2D.Tooltip]

func (*Plot2D) UpdatePlot

func (pl *Plot2D) UpdatePlot()

UpdatePlot updates the display based on current IdxView into table. This version can only be called within main goroutine for window eventloop -- use GoUpdateUplot for other-goroutine updates.

func (*Plot2D) XLabel

func (pl *Plot2D) XLabel() string

XLabel returns the X-axis label

func (*Plot2D) YLabel

func (pl *Plot2D) YLabel() string

YLabel returns the Y-axis label

type Plot2DValue

type Plot2DValue struct {
	giv.ValueBase
}

Plot2DValue presents a button that pulls up the Plot2D in a dialog

func (*Plot2DValue) ConfigDialog

func (vv *Plot2DValue) ConfigDialog(d *gi.Body) (bool, func())

func (*Plot2DValue) ConfigWidget

func (vv *Plot2DValue) ConfigWidget(w gi.Widget)

func (*Plot2DValue) HasDialog

func (vv *Plot2DValue) HasDialog() bool

func (*Plot2DValue) OpenDialog

func (vv *Plot2DValue) OpenDialog(ctx gi.Widget, fun func())

func (*Plot2DValue) UpdateWidget

func (vv *Plot2DValue) UpdateWidget()

func (*Plot2DValue) WidgetType

func (vv *Plot2DValue) WidgetType() *gti.Type

type PlotParams

type PlotParams struct {

	// optional title at top of plot
	Title string

	// type of plot to generate.  For a Bar plot, items are plotted ordinally by row and the XAxis is optional
	Type PlotTypes

	// whether to plot lines
	Lines bool

	// whether to plot points with symbols
	Points bool

	// width of lines
	LineWidth float64

	// size of points
	PointSize float64

	// the shape used to draw points
	PointShape Shapes

	// width of bars for bar plot, as fraction of available space -- 1 = no gaps, .8 default
	BarWidth float64 `min:"0.01" max:"1"`

	// draw lines that connect points with a negative X-axis direction -- otherwise these are treated as breaks between repeated series and not drawn
	NegXDraw bool

	// overall scaling factor -- the larger the number, the larger the fonts are relative to the graph
	Scale float64 `def:"2"`

	// what column to use for the common X axis -- if empty or not found, the row number is used.  This optional for Bar plots -- if present and LegendCol is also present, then an extra space will be put between X values.
	XAxisCol string

	// optional column for adding a separate colored / styled line or bar according to this value -- acts just like a separate Y variable, crossed with Y variables
	LegendCol string

	// rotation of the X Axis labels, in degrees
	XAxisRot float64

	// optional label to use for XAxis instead of column name
	XAxisLabel string

	// optional label to use for YAxis -- if empty, first column name is used
	YAxisLabel string

	// our plot, for update method
	Plot *Plot2D `copy:"-" json:"-" xml:"-" view:"-"`
}

PlotParams are parameters for overall plot

func (*PlotParams) CopyFrom

func (pp *PlotParams) CopyFrom(fr *PlotParams)

CopyFrom copies from other col params

func (*PlotParams) Defaults

func (pp *PlotParams) Defaults()

Defaults sets defaults if nil vals present

func (*PlotParams) FmMeta

func (pp *PlotParams) FmMeta(dt *etable.Table)

FmMeta sets plot params from meta data

func (*PlotParams) FmMetaMap

func (pp *PlotParams) FmMetaMap(meta map[string]string)

FmMetaMap sets plot params from meta data map

func (*PlotParams) Update

func (pp *PlotParams) Update()

Update satisfies the gi.Updater interface and will trigger display update on edits

type PlotTypes

type PlotTypes int32 //enums:enum

PlotTypes are different types of plots

const (
	// XY is a standard line / point plot
	XY PlotTypes = iota

	// Bar plots vertical bars
	Bar
)
const PlotTypesN PlotTypes = 2

PlotTypesN is the highest valid value for type PlotTypes, plus one.

func PlotTypesValues

func PlotTypesValues() []PlotTypes

PlotTypesValues returns all possible values for the type PlotTypes.

func (PlotTypes) Desc

func (i PlotTypes) Desc() string

Desc returns the description of the PlotTypes value.

func (PlotTypes) Int64

func (i PlotTypes) Int64() int64

Int64 returns the PlotTypes value as an int64.

func (PlotTypes) IsValid

func (i PlotTypes) IsValid() bool

IsValid returns whether the value is a valid option for type PlotTypes.

func (PlotTypes) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*PlotTypes) SetInt64

func (i *PlotTypes) SetInt64(in int64)

SetInt64 sets the PlotTypes value from an int64.

func (*PlotTypes) SetString

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

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

func (PlotTypes) String

func (i PlotTypes) String() string

String returns the string representation of this PlotTypes value.

func (*PlotTypes) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (PlotTypes) Values

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

Values returns all possible values for the type PlotTypes.

type Shapes

type Shapes int32 //enums:enum

Shapes are the different shapes that can be used for plot points.

const (
	// Ring is the outline of a circle
	Ring Shapes = iota

	// Circle is a solid circle
	Circle

	// Square is the outline of a square
	Square

	// Box is a filled square
	Box

	// Triangle is the outline of a triangle
	Triangle

	// Pyramid is a filled triangle
	Pyramid

	// Plus is a plus sign
	Plus

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

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

func ShapesValues

func ShapesValues() []Shapes

ShapesValues returns all possible values for the type Shapes.

func (Shapes) Desc

func (i Shapes) Desc() string

Desc returns the description of the Shapes value.

func (Shapes) Glyph

func (s Shapes) Glyph() draw.GlyphDrawer

Glyph returns the draw.GlyphDrawer associated with this shape.

func (Shapes) Int64

func (i Shapes) Int64() int64

Int64 returns the Shapes value as an int64.

func (Shapes) IsValid

func (i Shapes) IsValid() bool

IsValid returns whether the value is a valid option for type Shapes.

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 TableXY

type TableXY struct {

	// the index view of data table to plot from
	Table *etable.IdxView

	// the indexes of the tensor columns to use for the X and Y data, respectively
	XCol, YCol int

	// numer of elements in each row of data -- 1 for scalar, > 1 for multi-dimensional
	XRowSz, YRowSz int

	// the indexes of the element within each tensor cell if cells are n-dimensional, respectively
	XIdx, YIdx int

	// the column to use for returning a label using Label interface -- for string cols
	LblCol int

	// the column to use for returning errorbars (+/- given value) -- if YCol is tensor then this must also be a tensor and given YIdx used
	ErrCol int

	// range constraints on Y values
	YRange minmax.Range64
}

TableXY selects two columns from a etable.Table data table to plot in a gonum plot, satisfying the plotter.XYer and .Valuer interfaces (for bar charts). For Tensor-valued cells, Idx's specify tensor cell. Also satisfies the plotter.Labeler interface for labels attached to a line, and plotter.YErrorer for error bars.

func NewTableXY

func NewTableXY(dt *etable.IdxView, xcol, xtsrIdx, ycol, ytsrIdx int, yrng minmax.Range64) (*TableXY, error)

NewTableXY returns a new XY plot view onto the given IdxView of etable.Table (makes a copy), from given column indexes, and tensor indexes within each cell. Column indexes are enforced to be valid, with an error message if they are not.

func NewTableXYName

func NewTableXYName(dt *etable.IdxView, xi, xtsrIdx int, ycol string, ytsrIdx int, yrng minmax.Range64) (*TableXY, error)

NewTableXYName returns a new XY plot view onto the given IdxView of etable.Table (makes a copy), from given column name and tensor indexes within each cell. Column indexes are enforced to be valid, with an error message if they are not.

func (*TableXY) FilterVals

func (txy *TableXY) FilterVals()

FilterVals removes items with NaN values, and out of Y range

func (*TableXY) Label

func (txy *TableXY) Label(row int) string

Label returns a label for given row in table, using plotter.Labeler interface

func (*TableXY) Len

func (txy *TableXY) Len() int

Len returns the number of rows in the view of table

func (*TableXY) TRowValue

func (txy *TableXY) TRowValue(row int) float64

TRowValue returns the y value at given true table row in table view

func (*TableXY) TRowXValue

func (txy *TableXY) TRowXValue(row int) float64

TRowXValue returns an x value at given actual row in table

func (*TableXY) Validate

func (txy *TableXY) Validate() error

Validate returns error message if column indexes are invalid, else nil it also sets column indexes to 0 so nothing crashes.

func (*TableXY) Value

func (txy *TableXY) Value(row int) float64

Value returns the y value at given row in table view

func (*TableXY) XValue

func (txy *TableXY) XValue(row int) float64

XValue returns an x value at given row in table view

func (*TableXY) XY

func (txy *TableXY) XY(row int) (x, y float64)

XY returns an x, y pair at given row in table

func (*TableXY) YError

func (txy *TableXY) YError(row int) (float64, float64)

YError returns a error bars using ploter.YErrorer interface

Jump to

Keyboard shortcuts

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