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
- Variables
- func MetaMapLower(meta map[string]string, key string) (string, bool)
- func PlotViewSVG(plt *plot.Plot, svge *svg.Editor, scale float64)
- func SaveSVGView(fname string, plt *plot.Plot, svge *svg.Editor, scale float64) error
- func StringViewSVG(svgstr string, svge *svg.Editor, scale float64)
- type ColParams
- type ErrBarChart
- func (b *ErrBarChart) BarHeight(i int) float64
- func (b *ErrBarChart) DataRange() (xmin, xmax, ymin, ymax float64)
- func (b *ErrBarChart) Defaults()
- func (b *ErrBarChart) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
- func (b *ErrBarChart) Plot(c draw.Canvas, plt *plot.Plot)
- func (b *ErrBarChart) StackOn(on *ErrBarChart)
- func (b *ErrBarChart) Thumbnail(c *draw.Canvas)
- type Plot2D
- func (pl *Plot2D) ColParams(colNm string) *ColParams
- func (pl *Plot2D) ColParamsTry(colNm string) (*ColParams, error)
- func (pl *Plot2D) ColsConfig()
- func (pl *Plot2D) ColsLay() *gi.Frame
- func (pl *Plot2D) ColsListUpdate()
- func (pl *Plot2D) ColsUpdate()
- func (pl *Plot2D) Config()
- func (pl *Plot2D) CopyFieldsFrom(frm interface{})
- func (pl *Plot2D) Defaults()
- func (pl *Plot2D) GenPlot()
- func (pl *Plot2D) GenPlotBar()
- func (pl *Plot2D) GenPlotXY()
- func (pl *Plot2D) GoUpdate()
- func (pl *Plot2D) GoUpdatePlot()
- func (pl *Plot2D) IsConfiged() bool
- func (pl *Plot2D) Layout2D(parBBox image.Rectangle, iter int) bool
- func (pl *Plot2D) OpenCSV(fname gi.FileName, delim etable.Delims)
- func (pl *Plot2D) PlotConfig()
- func (pl *Plot2D) PlotLay() *gi.Layout
- func (pl *Plot2D) PlotXAxis(plt *plot.Plot, ixvw *etable.IdxView) (xi int, xview *etable.IdxView, xbreaks []int, err error)
- func (pl *Plot2D) SVGPlot() *svg.Editor
- func (pl *Plot2D) SaveAll(fname gi.FileName)
- func (pl *Plot2D) SaveCSV(fname gi.FileName, delim etable.Delims)
- func (pl *Plot2D) SavePNG(fname gi.FileName)
- func (pl *Plot2D) SaveSVG(fname gi.FileName)
- func (pl *Plot2D) SetAllCols(on bool)
- func (pl *Plot2D) SetColParams(colNm string, on bool, fixMin bool, min float64, fixMax bool, max float64) *ColParams
- func (pl *Plot2D) SetColsByName(nameContains string, on bool)
- func (pl *Plot2D) SetTable(tab *etable.Table)
- func (pl *Plot2D) SetTableView(tab *etable.IdxView)
- func (pl *Plot2D) Style2D()
- func (pl *Plot2D) Toolbar() *gi.ToolBar
- func (pl *Plot2D) ToolbarConfig()
- func (pl *Plot2D) Update()
- func (pl *Plot2D) UpdatePlot()
- func (pl *Plot2D) XLabel() string
- func (pl *Plot2D) YLabel() string
- type PlotParams
- type PlotTypes
- type TableXY
- func (txy *TableXY) FilterVals()
- func (txy *TableXY) Label(row int) string
- func (txy *TableXY) Len() int
- func (txy *TableXY) TRowValue(row int) float64
- func (txy *TableXY) TRowXValue(row int) float64
- func (txy *TableXY) Validate() error
- func (txy *TableXY) Value(row int) float64
- func (txy *TableXY) XValue(row int) float64
- func (txy *TableXY) XY(row int) (x, y float64)
- func (txy *TableXY) YError(row int) (float64, float64)
Constants ¶
const ( On bool = true Off = false FixMin = true FloatMin = false FixMax = true FloatMax = false )
use these for SetColParams args
const NColsHeader = 2
Variables ¶
var KiT_Plot2D = kit.Types.AddType(&Plot2D{}, Plot2DProps)
var KiT_PlotTypes = kit.Enums.AddEnum(PlotTypesN, kit.NotBitFlag, nil)
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", "Args": ki.PropSlice{ {"File Name", ki.Props{ "default-field": "SVGFile", "ext": ".svg", }}, }, }}, {"SavePNG", ki.Props{ "label": "Save PNG...", "desc": "save current render of plot to PNG file", "icon": "file-save", "Args": ki.PropSlice{ {"File Name", ki.Props{ "ext": ".png", }}, }, }}, {"SaveAll", ki.Props{ "label": "Save All...", "desc": "save plot to SVG, PNG, and TSV files", "icon": "file-save", "Args": ki.PropSlice{ {"File Name", ki.Props{ "default-field": "SVGFile", "ext": ".svg", }}, }, }}, {"OpenCSV", ki.Props{ "label": "Open CSV File...", "icon": "file-open", "desc": "Open CSV-formatted data (or any delimeter) -- also recognizes emergent-style headers", "Args": ki.PropSlice{ {"File Name", ki.Props{ "ext": ".tsv,.csv", }}, {"Delimiter", ki.Props{ "default": etable.Tab, "desc": "delimiter between columns", }}, }, }}, {"SaveCSV", ki.Props{ "label": "Save Data...", "icon": "file-save", "desc": "Save CSV-formatted data (or any delimiter) -- header outputs emergent-style header data (recommended)", "Args": ki.PropSlice{ {"File Name", ki.Props{ "default-field": "DataFile", "ext": ".tsv,.csv", }}, {"Delimiter", ki.Props{ "default": etable.Tab, "desc": "delimiter between columns", }}, }, }}, }, "CallMethods": ki.PropSlice{ {"SetColsByName", ki.Props{ "desc": "Turn columns containing given string On or Off", "Args": ki.PropSlice{ {"Name Contains", ki.Props{}}, {"On", ki.Props{ "default": true, }}, }, }}, }, }
var PlotColorNames = []string{"black", "red", "blue", "ForestGreen", "purple", "orange", "brown", "chartreuse", "navy", "cyan", "magenta", "tan", "salmon", "goldenrod", "SkyBlue", "pink"}
these are the plot color names to use in order for successive lines -- feel free to choose your own!
Functions ¶
func MetaMapLower ¶ added in v1.0.43
MetaMapLower tries meta data access by lower-case version of key too
func PlotViewSVG ¶
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 ¶
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.
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 gist.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 `` /* 153-byte string literal not displayed */ ErrCol string `desc:"specifies a column containing error bars for this column"` IsString bool `inactive:"+" desc:"if true this is a string column -- plots as labels"` 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) 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 ErrBarChart ¶ added in v1.0.6
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 ¶ added in v1.0.6
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 ¶ added in v1.0.6
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 ¶ added in v1.0.6
func (b *ErrBarChart) DataRange() (xmin, xmax, ymin, ymax float64)
DataRange implements the plot.DataRanger interface.
func (*ErrBarChart) Defaults ¶ added in v1.0.6
func (b *ErrBarChart) Defaults()
func (*ErrBarChart) GlyphBoxes ¶ added in v1.0.6
func (b *ErrBarChart) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox
GlyphBoxes implements the GlyphBoxer interface.
func (*ErrBarChart) Plot ¶ added in v1.0.6
func (b *ErrBarChart) Plot(c draw.Canvas, plt *plot.Plot)
Plot implements the plot.Plotter interface.
func (*ErrBarChart) StackOn ¶ added in v1.0.6
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 ¶ added in v1.0.6
func (b *ErrBarChart) Thumbnail(c *draw.Canvas)
Thumbnail fulfills the plot.Thumbnailer interface.
type Plot2D ¶
type Plot2D struct { gi.Layout Table *etable.IdxView `desc:"the idxview of 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 `inactive:"+" desc:"currently doing a plot"` }
Plot2D is a GoGi Widget that provides a 2D plot of selected columns of etable data
func AddNewPlot2D ¶
AddNewPlot2D adds a new Plot2D to given parent node, with given name.
func (*Plot2D) 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 ¶
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) 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) CopyFieldsFrom ¶ added in v1.0.0
func (pl *Plot2D) CopyFieldsFrom(frm interface{})
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 ¶ added in v1.0.0
func (pl *Plot2D) GenPlotBar()
GenPlotBar generates a Bar plot, setting GPlot variable
func (*Plot2D) GenPlotXY ¶ added in v1.0.0
func (pl *Plot2D) GenPlotXY()
GenPlotXY generates an XY (lines, points) plot, setting GPlot variable
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) GoUpdatePlot ¶ added in v1.0.0
func (pl *Plot2D) GoUpdatePlot()
GoUpdatePlot updates the display based on current IdxView into 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 ¶
IsConfiged returns true if widget is fully configured
func (*Plot2D) OpenCSV ¶ added in v1.0.0
OpenCSV opens the Table data from a csv (comma-separated values) file (or any delim)
func (*Plot2D) PlotXAxis ¶ added in v1.0.0
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) SaveAll ¶ added in v1.0.44
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 ¶ added in v1.0.0
SaveCSV saves the Table data to a csv (comma-separated values) file with headers (any delim)
func (*Plot2D) SavePNG ¶ added in v1.0.1
SavePNG saves the current plot to a png, capturing current render
func (*Plot2D) SaveSVG ¶
SaveSVG saves the plot to an svg -- first updates to ensure that plot is current
func (*Plot2D) SetAllCols ¶ added in v1.0.8
SetAllCols turns all Cols on or off (except X axis)
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 ¶ added in v1.0.8
SetColsByName turns cols On or Off if their name contains given string
func (*Plot2D) SetTableView ¶ added in v1.0.0
SetTableView sets the idxview of table to view and updates view
func (*Plot2D) ToolbarConfig ¶
func (pl *Plot2D) ToolbarConfig()
func (*Plot2D) Update ¶
func (pl *Plot2D) Update()
Update updates the display based on current state of table. Calls Sequential method on etable.IdxView to view entire current table. This version can only be called within main goroutine for window eventloop -- use GoUpdate for other-goroutine updates.
func (*Plot2D) UpdatePlot ¶ added in v1.0.0
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 GoUpdate for other-goroutine updates.
type PlotParams ¶
type PlotParams struct { Title string `desc:"optional title at top of plot"` Type PlotTypes `desc:"type of plot to generate. For a Bar plot, items are plotted ordinally by row and the XAxis is optional"` Lines bool `desc:"plot lines"` Points bool `desc:"plot points with symbols"` LineWidth float64 `desc:"width of lines"` PointSize float64 `desc:"size of points"` BarWidth float64 `min:"0.01" max:"1" desc:"width of bars for bar plot, as fraction of available space -- 1 = no gaps, .8 default"` NegXDraw bool `` /* 149-byte string literal not displayed */ Scale float64 `def:"2" desc:"overall scaling factor -- the larger the number, the larger the fonts are relative to the graph"` XAxisCol string `` /* 221-byte string literal not displayed */ LegendCol string `` /* 163-byte string literal not displayed */ XAxisRot float64 `desc:"rotation of the X Axis labels, in degrees"` 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) CopyFrom ¶ added in v1.0.0
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 ¶ added in v1.0.0
func (pp *PlotParams) FmMeta(dt *etable.Table)
FmMeta sets plot params from meta data
func (*PlotParams) FmMetaMap ¶ added in v1.0.43
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 ¶ added in v1.0.0
type PlotTypes int32
PlotTypes are different types of plots
func (*PlotTypes) FromString ¶ added in v1.0.0
func (PlotTypes) MarshalJSON ¶ added in v1.0.0
func (*PlotTypes) UnmarshalJSON ¶ added in v1.0.0
type TableXY ¶
type TableXY struct { Table *etable.IdxView `desc:"the index view of data table to plot from"` XCol, YCol int `desc:"the indexes of the tensor columns to use for the X and Y data, respectively"` XRowSz, YRowSz int `desc:"numer of elements in each row of data -- 1 for scalar, > 1 for multi-dimensional"` XIdx, YIdx int `desc:"the indexes of the element within each tensor cell if cells are n-dimensional, respectively"` LblCol int `desc:"the column to use for returning a label using Label interface -- for string cols"` ErrCol int `` /* 139-byte string literal not displayed */ YRange minmax.Range64 `desc:"range constraints on Y values"` }
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 ¶ added in v1.0.0
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 ¶ added in v1.0.0
func (txy *TableXY) FilterVals()
FilterVals removes items with NaN values, and out of Y range
func (*TableXY) Label ¶ added in v1.0.0
Label returns a label for given row in table, using plotter.Labeler interface
func (*TableXY) TRowValue ¶ added in v1.0.0
TRowValue returns the y value at given true table row in table view
func (*TableXY) TRowXValue ¶ added in v1.0.0
TRowXValue returns an x value at given actual row in table
func (*TableXY) Validate ¶
Validate returns error message if column indexes are invalid, else nil it also sets column indexes to 0 so nothing crashes.