eplot

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: BSD-3-Clause Imports: 20 Imported by: 146

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

This section is empty.

Variables

View Source
var KiT_Plot2D = kit.Types.AddType(&Plot2D{}, Plot2DProps)
View Source
var Plot2DProps = ki.Props{
	"max-width":  -1,
	"max-height": -1,

	"ToolBar": ki.PropSlice{
		{"Update", ki.Props{
			"shortcut": "Command+U",
			"desc":     "update graph plot",
			"icon":     "update",
		}},

		{"SaveSVG", ki.Props{
			"label": "Save SVG...",
			"desc":  "save plot to an SVG file",
			"icon":  "file-save",
			"shortcut-func": giv.ShortcutFunc(func(gei interface{}, act *gi.Action) key.Chord {
				return key.Chord(gide.ChordForFun(gide.KeyFunBufSaveAs).String())
			}),
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"default-field": "SVGFile",
					"ext":           ".svg",
				}},
			},
		}},
		{"SaveData", ki.Props{
			"label": "Save Data...",
			"icon":  "file-save",
			"desc":  "save table data to a csv comma-separated-values file",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"default-field": "DataFile",
					"ext":           ".csv",
				}},
			},
		}},
	},
}
View Source
var PlotColorNames = []string{"black", "red", "blue", "ForestGreen", "purple", "orange", "brown", "chartreuse", "navy", "cyan", "magenta", "tan", "salmon", "yellow4", "SkyBlue", "pink"}

these are the plot color names to use in order for successive lines -- feel free to choose your own!

Functions

func PlotViewSVG

func PlotViewSVG(plt *plot.Plot, svge *svg.Editor, 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 *svg.Editor, 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 *svg.Editor, 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 {
	On        bool           `desc:"plot this column"`
	Col       string         `desc:"name of column we're plotting"`
	Range     minmax.Range64 `desc:"effective range of data to plot -- either end can be fixed"`
	FullRange minmax.F64     `desc:"full actual range of data -- only valid if specifically computed"`
	ColorName gi.ColorName   `desc:"if non-empty, color is set by this name"`
	Color     gi.Color       `desc:"color to use in plotting the line"`
	NTicks    int            `desc:"desired number of ticks"`
	Lbl       string         `desc:"if non-empty, this is an alternative label to use in plotting"`
	TensorIdx int            `desc:"if column has n-dimensional tensor cells in each row, this is the index within each cell to plot"`
	ErrCol    string         `desc:"specifies a column containing error bars for this column"`
	Plot      *Plot2D        `copy:"-" json:"-" xml:"-" view:"-" desc:"our plot, for update method"`
}

ColParams are parameters for plotting one column of data

func (*ColParams) Defaults

func (cp *ColParams) Defaults()

Defaults sets defaults if nil vals present

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

func (*ColParams) UpdateVals

func (cp *ColParams) UpdateVals()

UpdateVals update derived values e.g., color from color name

type Plot2D

type Plot2D struct {
	gi.Layout
	Table    *etable.Table `desc:"the table that we're plotting"`
	Params   PlotParams    `desc:"the overall plot parameters"`
	Cols     []*ColParams  `desc:"the parameters for each column of the table"`
	GPlot    *plot.Plot    `desc:"the gonum plot that actually does the plotting -- always save the last one generated"`
	SVGFile  gi.FileName   `desc:"current svg file"`
	DataFile gi.FileName   `desc:"current csv data file"`
	InPlot   bool          `desc:"currently doing a plot"`
}

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

func AddNewPlot2D

func AddNewPlot2D(parent ki.Ki, name string) *Plot2D

AddNewPlot2D adds a new Plot2D to given parent node, with given name.

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) 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) Config

func (pl *Plot2D) Config()

Config configures the overall view widget

func (*Plot2D) Defaults

func (pl *Plot2D) Defaults()

func (*Plot2D) GenPlot

func (pl *Plot2D) GenPlot()

GenPlot generates the plot if blockUpdts is true, then block any other updates on the parent Viewport while we're plotting, because this involves destroying and rebuilding the tree, and is often called from another goroutine. if called as part of the normal render process (e.g., in Style2D, then do NOT block updates!)

func (*Plot2D) GoUpdate

func (pl *Plot2D) GoUpdate()

GoUpdate updates the display based on current state of table. This version must be used when called from another goroutine does proper blocking to synchronize with updating in the main goroutine.

func (*Plot2D) IsConfiged

func (pl *Plot2D) IsConfiged() bool

IsConfiged returns true if widget is fully configured

func (*Plot2D) PlotConfig

func (pl *Plot2D) PlotConfig()

PlotConfig configures the PlotView

func (*Plot2D) PlotLay

func (pl *Plot2D) PlotLay() *gi.Layout

func (*Plot2D) SVGPlot

func (pl *Plot2D) SVGPlot() *svg.Editor

func (*Plot2D) SaveData

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

SaveData saves the Table data to a csv (comma-separated values) file

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) SetColParams

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

SetColParams sets main parameters for one column

func (*Plot2D) SetTable

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

SetTable sets the table to view and updates view

func (*Plot2D) Style2D

func (pl *Plot2D) Style2D()

func (*Plot2D) Toolbar

func (pl *Plot2D) Toolbar() *gi.ToolBar

func (*Plot2D) ToolbarConfig

func (pl *Plot2D) ToolbarConfig()

func (*Plot2D) Update

func (pl *Plot2D) Update()

Update updates the display based on current state of table. This version can only be called within main goroutine for window eventloop -- use GoUpdate 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 PlotParams

type PlotParams struct {
	Title      string  `desc:"optional title at top of plot"`
	LineWidth  float64 `desc:"width of lines"`
	Scale      float64 `def:"2" desc:"overall scaling factor -- the larger the number, the larger the fonts are relative to the graph"`
	XAxisCol   string  `desc:"what column to use for the common x axis -- if empty or not found, the row number is used"`
	XAxisLabel string  `desc:"optional label to use for XAxis instead of column name"`
	YAxisLabel string  `desc:"optional label to use for YAxis -- if empty, first column name is used"`
	Plot       *Plot2D `copy:"-" json:"-" xml:"-" view:"-" desc:"our plot, for update method"`
}

PlotParams are parameters for overall plot

func (*PlotParams) Defaults

func (pp *PlotParams) Defaults()

Defaults sets defaults if nil vals present

func (*PlotParams) Update

func (pp *PlotParams) Update()

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

type TableXY

type TableXY struct {
	Table      *etable.Table `desc:"the data table to plot from"`
	XCol, YCol int           `desc:"the indexes of the tensor columns to use for the X and Y data, respectively"`
	XIdx, YIdx int           `desc:"the indexes of the element within each tensor cell if cells are n-dimensional, respectively"`
}

TableXY selects two 1D columns (i.e., scalar cells) from a etable.Table data table to plot in a gonum plot, satisfying the plotter.XYer interface

func NewTableXY

func NewTableXY(dt *etable.Table, xcol, ycol int) (*TableXY, error)

NewTableXY returns a new XY plot view onto the given etable.Table, from given column indexes. Column indexes are enforced to be valid, with an error message if they are not.

func NewTableXYNames

func NewTableXYNames(dt *etable.Table, xcol, ycol string) (*TableXY, error)

NewTableXYNames returns a new XY plot view onto the given etable.Table, from given column names Column indexes are enforced to be valid, with an error message if they are not.

func (*TableXY) Len

func (txy *TableXY) Len() int

Len returns the number of rows in the 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) XY

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

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

Jump to

Keyboard shortcuts

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