Documentation ¶
Overview ¶
Package plotcore provides Cogent Core widgets for viewing and editing plots.
Index ¶
- Constants
- type ColumnOptions
- type Plot
- type PlotEditor
- func (pl *PlotEditor) ColumnOptions(column string) *ColumnOptions
- func (pl *PlotEditor) ColumnsFromMetaMap(meta map[string]string)
- func (pl *PlotEditor) CopyFieldsFrom(frm tree.Node)
- func (pl *PlotEditor) GoUpdatePlot()
- func (pl *PlotEditor) Init()
- func (pl *PlotEditor) MakeToolbar(p *tree.Plan)
- func (pl *PlotEditor) OpenCSV(filename core.Filename, delim table.Delims)
- func (pl *PlotEditor) OpenFS(fsys fs.FS, filename core.Filename, delim table.Delims)
- func (pl *PlotEditor) SaveAll(fname core.Filename)
- func (pl *PlotEditor) SaveCSV(fname core.Filename, delim table.Delims)
- func (pl *PlotEditor) SavePNG(fname core.Filename)
- func (pl *PlotEditor) SaveSVG(fname core.Filename)
- func (pl *PlotEditor) SetColumnOptions(column string, on bool, fixMin bool, min float32, fixMax bool, max float32) *ColumnOptions
- func (t *PlotEditor) SetOptions(v PlotOptions) *PlotEditor
- func (pl *PlotEditor) SetSlice(sl any) *PlotEditor
- func (pl *PlotEditor) SetTable(tab *table.Table) *PlotEditor
- func (pt *PlotEditor) SizeFinal()
- func (pl *PlotEditor) UpdatePlot()
- type PlotOptions
- type PlotTypes
- func (i PlotTypes) Desc() string
- func (i PlotTypes) Int64() int64
- func (i PlotTypes) MarshalText() ([]byte, error)
- func (i *PlotTypes) SetInt64(in int64)
- func (i *PlotTypes) SetString(s string) error
- func (i PlotTypes) String() string
- func (i *PlotTypes) UnmarshalText(text []byte) error
- func (i PlotTypes) Values() []enums.Enum
Constants ¶
const ( On = true Off = false FixMin = true FloatMin = false FixMax = true FloatMax = false )
Bool constants for PlotEditor.SetColumnOptions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnOptions ¶ added in v0.2.1
type ColumnOptions struct { // whether to plot this column On bool // name of column being plotting Column string // 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[float32] // the size of points; uses the overall plot option if unset PointSize option.Option[float32] // the shape used to draw points; uses the overall plot option if unset PointShape option.Option[plots.Shapes] // effective range of data to plot -- either end can be fixed Range minmax.Range32 `display:"inline"` // full actual range of data -- only valid if specifically computed FullRange minmax.F32 `display:"inline"` // color to use when plotting the line / column Color image.Image // desired number of ticks NTicks int // if specified, this is an alternative label to use when plotting Label string // 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 TensorIndex int // specifies a column containing error bars for this column ErrColumn string // if true this is a string column -- plots as labels IsString bool `edit:"-"` }
ColumnOptions are options for plotting one column of data.
type Plot ¶
type Plot struct { core.WidgetBase // 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 // Plot is the Plot to display in this widget Plot *plot.Plot `set:"-"` // SetRangesFunc, if set, is called to adjust the data ranges // after the point when these ranges are updated based on the plot data. SetRangesFunc func() }
Plot is a widget that renders a plot.Plot object. If it is not states.ReadOnly, the user can pan and zoom the graph. See PlotEditor for an interactive interface for selecting columns to view.
func NewPlot ¶
NewPlot returns a new Plot with the given optional parent: Plot is a widget that renders a plot.Plot object. If it is not states.ReadOnly, the user can pan and zoom the graph. See PlotEditor for an interactive interface for selecting columns to view.
func (*Plot) SetPlot ¶
SetPlot sets the plot to given Plot, and calls UpdatePlot to ensure it is drawn at the current size of this widget
func (*Plot) SetScale ¶
SetScale sets the [Plot.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.
type PlotEditor ¶
type PlotEditor struct { core.Frame // Options are the overall plot options. Options PlotOptions // Columns are the options for each column of the table. Columns []*ColumnOptions `set:"-"` // contains filtered or unexported fields }
PlotEditor is a widget that provides an interactive 2D plot of selected columns of tabular data, represented by a table.IndexView into a table.Table. Other types of tabular data can be converted into this format. The user can change various options for the plot and also modify the underlying data.
func NewPlotEditor ¶
func NewPlotEditor(parent ...tree.Node) *PlotEditor
NewPlotEditor returns a new PlotEditor with the given optional parent: PlotEditor is a widget that provides an interactive 2D plot of selected columns of tabular data, represented by a table.IndexView into a table.Table. Other types of tabular data can be converted into this format. The user can change various options for the plot and also modify the underlying data.
func NewSubPlot ¶
func NewSubPlot(parent ...tree.Node) *PlotEditor
NewSubPlot returns a PlotEditor with its own separate core.Toolbar, suitable for a tab or other element that is not the main plot.
func (*PlotEditor) ColumnOptions ¶ added in v0.2.1
func (pl *PlotEditor) ColumnOptions(column string) *ColumnOptions
ColumnOptions returns the current column options by name (to access by index, just use Columns directly).
func (*PlotEditor) ColumnsFromMetaMap ¶
func (pl *PlotEditor) ColumnsFromMetaMap(meta map[string]string)
ColumnsFromMetaMap updates all the column settings from given meta map
func (*PlotEditor) CopyFieldsFrom ¶
func (pl *PlotEditor) CopyFieldsFrom(frm tree.Node)
func (*PlotEditor) GoUpdatePlot ¶
func (pl *PlotEditor) GoUpdatePlot()
GoUpdatePlot updates the display based on current IndexView into table. This version can be called from goroutines. It does Sequential() on the table.IndexView, under the assumption that it is used for tracking a the latest updates of a running process.
func (*PlotEditor) Init ¶
func (pl *PlotEditor) Init()
func (*PlotEditor) MakeToolbar ¶
func (pl *PlotEditor) MakeToolbar(p *tree.Plan)
func (*PlotEditor) OpenCSV ¶
func (pl *PlotEditor) OpenCSV(filename core.Filename, delim table.Delims)
OpenCSV opens the Table data from a csv (comma-separated values) file (or any delim)
func (*PlotEditor) OpenFS ¶
OpenFS opens the Table data from a csv (comma-separated values) file (or any delim) from the given filesystem.
func (*PlotEditor) SaveAll ¶
func (pl *PlotEditor) SaveAll(fname core.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 (*PlotEditor) SaveCSV ¶
func (pl *PlotEditor) SaveCSV(fname core.Filename, delim table.Delims)
SaveCSV saves the Table data to a csv (comma-separated values) file with headers (any delim)
func (*PlotEditor) SavePNG ¶
func (pl *PlotEditor) SavePNG(fname core.Filename)
SavePNG saves the current plot to a png, capturing current render
func (*PlotEditor) SaveSVG ¶
func (pl *PlotEditor) SaveSVG(fname core.Filename)
SaveSVG saves the plot to an svg -- first updates to ensure that plot is current
func (*PlotEditor) SetColumnOptions ¶ added in v0.2.1
func (pl *PlotEditor) SetColumnOptions(column string, on bool, fixMin bool, min float32, fixMax bool, max float32) *ColumnOptions
SetColumnOptions sets the main parameters for one column.
func (*PlotEditor) SetOptions ¶ added in v0.2.1
func (t *PlotEditor) SetOptions(v PlotOptions) *PlotEditor
SetOptions sets the [PlotEditor.Options]: Options are the overall plot options.
func (*PlotEditor) SetSlice ¶ added in v0.3.0
func (pl *PlotEditor) SetSlice(sl any) *PlotEditor
SetSlice sets the table to a table.NewSliceTable from the given slice.
func (*PlotEditor) SetTable ¶
func (pl *PlotEditor) SetTable(tab *table.Table) *PlotEditor
SetTable sets the table to view and does Update to update the Column list, which will also trigger a Layout and updating of the plot on next render pass. This is safe to call from a different goroutine.
func (*PlotEditor) SizeFinal ¶
func (pt *PlotEditor) SizeFinal()
func (*PlotEditor) UpdatePlot ¶
func (pl *PlotEditor) UpdatePlot()
UpdatePlot updates the display based on current IndexView into table. It does not automatically update the table.IndexView unless it is nil or out date.
type PlotOptions ¶ added in v0.2.1
type PlotOptions 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 `default:"true"` // whether to plot points with symbols Points bool // width of lines LineWidth float32 `default:"1"` // size of points PointSize float32 `default:"3"` // the shape used to draw points PointShape plots.Shapes // width of bars for bar plot, as fraction of available space (1 = no gaps) BarWidth float32 `min:"0.01" max:"1" default:"0.8"` // if true, 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. NegativeXDraw bool // 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"` // 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 // Legend is also present, then an extra space will be put between X values. XAxis string // optional column for adding a separate colored / styled line or bar // according to this value, and acts just like a separate Y variable, // crossed with Y variables. Legend string // position of the Legend LegendPosition plot.LegendPosition `display:"inline"` // rotation of the X Axis labels, in degrees XAxisRotation float32 // 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 }
PlotOptions are options for the overall plot.
func (*PlotOptions) FromMetaMap ¶ added in v0.2.1
func (po *PlotOptions) FromMetaMap(meta map[string]string)
FromMetaMap sets plot options from meta data map.
type PlotTypes ¶
type PlotTypes int32 //enums:enum
PlotTypes are different types of plots.
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) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*PlotTypes) SetString ¶
SetString sets the PlotTypes value from its string representation, and returns an error if the string is invalid.
func (*PlotTypes) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.