plot #
VSL Plot
This library implements high-level functions to generate plots and drawings.
vsl.plot
follows the structure of Plotly's graph_objects. Check the examples folder and compare it to Plotly's Python examples for a better understanding.
Supported Graph Types
- Bar
- Heatmap
- Histogram
- Pie
- Scatter
- Scatter 3D
- Surface
fn Plot.new #
fn Plot.new() &Plot
type Trace #
type Trace = BarTrace
| HeatmapTrace
| HistogramTrace
| PieTrace
| Scatter3DTrace
| ScatterTrace
| SurfaceTrace
Trace is a sum type for representing different trace types
fn (Trace) trace_type #
fn (t Trace) trace_type() string
type XType #
type XType = []f64 | []int | []string
XType is a type for x-axis data
type YType #
type YType = []f64 | []int | []string
YType is a type for y-axis data
type ZType #
type ZType = [][]f64 | [][]int | []f64 | []int
ZType is a type for z-axis data
enum TraceType #
enum TraceType {
scatter
pie
heatmap
surface
scatter3d
bar
histogram
}
Enum for trace types
struct Annotation #
struct Annotation {
pub mut:
x f64 @[omitempty]
y f64 @[omitempty]
text string @[required]
showarrow bool
arrowhead int @[omitempty]
arrowcolor string @[omitempty]
align string @[omitempty]
font Font
}
Annotation handles all the information needed to annotate plots
struct Axis #
struct Axis {
pub mut:
title AxisTitle
tickmode string = 'auto'
tick0 f64 @[omitempty]
dtick f64 @[omitempty]
tickvals []f64 @[omitempty]
ticktext []string @[omitempty]
range []f64 @[omitempty]
}
Axis handles axis data
struct AxisTitle #
struct AxisTitle {
pub mut:
text string
}
AxisTitle handles needed data to render an axis title
struct BarTrace #
struct BarTrace {
CommonTrace
}
BarTrace is a struct for Bar trace type
struct Bins #
struct Bins {
pub mut:
start f64
end f64
size f64
}
Bins is a struct for bin limits in a histogram trace
struct CommonTrace #
struct CommonTrace {
pub mut:
x XType
xbins map[string]f32
y YType @[omitempty]
z ZType @[omitempty]
name string @[omitempty]
mode string @[omitempty]
marker Marker @[omitempty]
line Line @[omitempty]
pull []f64 @[omitempty]
hole f64 @[omitempty]
fill string @[omitempty]
fillcolor string @[omitempty]
customdata [][]string @[omitempty]
colorscale string = 'Viridis' @[omitempty]
textinfo string @[omitempty]
text []string @[omitempty]
}
CommonTrace is a struct for common trace properties
struct Font #
struct Font {
pub mut:
color string = 'black'
family string = 'monospace'
size f64 = 16.0
}
Font handles data to customize fonts
struct HeatmapTrace #
struct HeatmapTrace {
CommonTrace
pub mut:
hovertemplate string @[omitempty]
zsmooth string @[omitempty]
}
HeatmapTrace is a struct for Heatmap trace type
struct HistogramTrace #
struct HistogramTrace {
CommonTrace
pub mut:
nbinsx int @[omitempty]
nbinsy int @[omitempty]
xbins Bins @[omitempty]
histfunc string @[omitempty]
marker Marker @[omitempty]
}
HistogramTrace is a struct for Histogram trace type
struct Layout #
struct Layout {
pub mut:
title string
title_x f64
autosize bool
width int = 550
height int = 550
xaxis Axis
yaxis Axis
annotations []Annotation
}
Layout
struct Line #
struct Line {
pub mut:
color string @[omitempty]
width f64 = 2.0 @[omitempty]
dash string = 'solid' @[omitempty]
}
Line is a struct for line properties in a trace
struct Marker #
struct Marker {
pub mut:
size []f64 @[omitempty]
color []string @[omitempty]
opacity f64 = 0.8 @[omitempty]
colorscale string = 'Viridis' @[omitempty]
}
Marker is a struct for marker properties in a trace
struct PieTrace #
struct PieTrace {
CommonTrace
pub mut:
values []f64 @[omitempty]
labels []string @[omitempty]
}
PieTrace is a struct for Pie trace type
struct Plot #
struct Plot {
pub mut:
traces []Trace
layout Layout
}
Plot is the main structure that contains layout and traces to generate plots
fn (Plot) annotation #
fn (mut p Plot) annotation(annotation Annotation) Plot
box adds a box trace to the plot
fn (Plot) bar #
fn (mut p Plot) bar(trace BarTrace) Plot
bar adds a bar trace to the plot
fn (Plot) get_plotly_script #
fn (p Plot) get_plotly_script(element_id string, config PlotlyScriptConfig) &html.Tag
get_plotly_script returns the plot script as an html tag.
fn (Plot) heatmap #
fn (mut p Plot) heatmap(trace HeatmapTrace) Plot
heatmap adds a heatmap trace to the plot
fn (Plot) histogram #
fn (mut p Plot) histogram(trace HistogramTrace) Plot
histogram adds a histogram trace to the plot
fn (Plot) layout #
fn (mut p Plot) layout(layout Layout) Plot
layout sets the layout of the plot
fn (Plot) pie #
fn (mut p Plot) pie(trace PieTrace) Plot
pie adds a pie trace to the plot
fn (Plot) scatter #
fn (mut p Plot) scatter(trace ScatterTrace) Plot
scatter adds a scatter trace to the plot
fn (Plot) scatter3d #
fn (mut p Plot) scatter3d(trace Scatter3DTrace) Plot
scatter3d adds a scatter3d trace to the plot. If the z value is a 2D array, it is flattened to a 1D array
fn (Plot) show #
fn (p Plot) show(config PlotConfig) !
show starts a web server and opens a browser window to display the plot.
fn (Plot) surface #
fn (mut p Plot) surface(trace SurfaceTrace) Plot
surface adds a surface trace to the plot
struct PlotConfig #
struct PlotConfig {
net.ListenOptions
pub:
timeout time.Duration = 1 * time.second
use_cdn bool
saddr string = ':0'
}
PlotConfig is a configuration for the Plotly plot. It includes the configuration for the web server that serves the plot.
struct PlotlyScriptConfig #
struct PlotlyScriptConfig {
PlotConfig
}
PlotlyScriptConfig is a configuration for the Plotly plot script.
struct Scatter3DTrace #
struct Scatter3DTrace {
CommonTrace
}
Scatter3DTrace is a struct for Scatter3D trace type
struct ScatterTrace #
struct ScatterTrace {
CommonTrace
}
ScatterTrace is a struct for Scatter trace type
struct SurfaceTrace #
struct SurfaceTrace {
CommonTrace
pub mut:
hovertemplate string @[omitempty]
}
SurfaceTrace is a struct for Surface trace type
- README
- fn Plot.new
- type Trace
- type XType
- type YType
- type ZType
- enum TraceType
- struct Annotation
- struct Axis
- struct AxisTitle
- struct BarTrace
- struct Bins
- struct CommonTrace
- struct Font
- struct HeatmapTrace
- struct HistogramTrace
- struct Layout
- struct Line
- struct Marker
- struct PieTrace
- struct Plot
- struct PlotConfig
- struct PlotlyScriptConfig
- struct Scatter3DTrace
- struct ScatterTrace
- struct SurfaceTrace