plot #
VSL Plot Module 📊
This library implements high-level plotting functions for scientific data visualization using a Plotly-inspired API. Create interactive, publication-quality plots with minimal code while maintaining full customization control.
🚀 Features
Core Plot Types
- Scatter Plots: Points, lines, or combined with extensive marker customization
- Line Charts: Time series and continuous data visualization
- Bar Charts: Vertical and horizontal bars with grouping support
- Histograms: Distribution visualization with binning control
- Pie Charts: Proportion visualization with labels and annotations
- Heatmaps: 2D data visualization with color mapping
- 3D Scatter: Three-dimensional data visualization
- Surface Plots: 3D surface rendering for mathematical functions
Statistical & Distribution Charts
- Box Plots: Statistical distribution analysis with quartiles
- Violin Plots: Kernel density estimation for distributions
- Contour Plots: Topographical and mathematical contour visualization
Business & Financial Charts
- Waterfall Charts: Financial flow and variance analysis
- Candlestick Charts: OHLC stock price visualization
- Funnel Charts: Conversion and process flow analysis
Hierarchical & Network Charts
- Sunburst Charts: Hierarchical data with radial layout
- Treemap Charts: Hierarchical data with nested rectangles
- Sankey Diagrams: Flow and process visualization
- Network Graphs: Node-link relationship visualization
Advanced Analytics
- Radar/Polar Charts: Multi-dimensional comparison
- Parallel Coordinates: High-dimensional data analysis
- 2D Histograms: Bivariate distribution analysis
- Density Plots: Continuous probability distributions
- Ridgeline Plots: Multiple distribution comparison
Geographic & Mapping
- Choropleth Maps: Geographic data visualization
- Scatter Mapbox: Location-based scatter plots
- Density Mapbox: Geographic density visualization
Interactive Features
- Zoom & Pan: Mouse-driven plot navigation
- Hover Information: Dynamic data point details
- Legend Control: Show/hide data series
- Export Options: Save as PNG, SVG, or HTML
- Responsive Design: Automatic layout adjustment
📖 Quick Start
Basic Scatter Plot
import vsl.plot
import vsl.util
// Generate data
x := util.arange(10).map(f64(it))
y := x.map(it * it) // y = x²
// Create plot
mut plt := plot.Plot.new()
plt.scatter(x: x, y: y, mode: 'lines+markers')
plt.layout(title: 'Quadratic Function')
plt.show()!
Line Chart (Time Series)
import vsl.plot
dates := ['2024-01', '2024-02', '2024-03', '2024-04']
prices := [100.0, 120.0, 110.0, 130.0]
mut plt := plot.Plot.new()
plt.line(x: dates, y: prices, mode: 'lines+markers')
plt.layout(title: 'Stock Price Trend')
plt.show()!
Box Plot (Statistical Analysis)
import vsl.plot
data1 := [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
data2 := [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
mut plt := plot.Plot.new()
plt.box(y: data1, name: 'Dataset A')
plt.box(y: data2, name: 'Dataset B')
plt.layout(title: 'Distribution Comparison')
plt.show()!
Violin Plot (Distribution Shape)
import vsl.plot
values := [1.0, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]
mut plt := plot.Plot.new()
plt.violin(y: values, name: 'Distribution')
plt.layout(title: 'Data Distribution Shape')
plt.show()!
Candlestick Chart (Financial)
import vsl.plot
dates := ['2024-01-01', '2024-01-02', '2024-01-03']
open_prices := [100.0, 105.0, 102.0]
high_prices := [110.0, 108.0, 107.0]
low_prices := [95.0, 100.0, 98.0]
close_prices := [105.0, 102.0, 106.0]
mut plt := plot.Plot.new()
plt.candlestick(
x: dates
open: open_prices
high: high_prices
low: low_prices
close: close_prices
)
plt.layout(title: 'Stock Price OHLC')
plt.show()!
Sunburst Chart (Hierarchical Data)
import vsl.plot
mut plt := plot.Plot.new()
plt.sunburst(
labels: ['Root', 'A', 'B', 'A1', 'A2', 'B1']
parents: ['', 'Root', 'Root', 'A', 'A', 'B']
values: [100.0, 60.0, 40.0, 30.0, 30.0, 40.0]
)
plt.layout(title: 'Hierarchical Structure')
plt.show()!
Choropleth Map (Geographic)
import vsl.plot
state_codes := ['CA', 'TX', 'NY', 'FL']
population := [39500000.0, 29000000.0, 19500000.0, 21500000.0]
mut plt := plot.Plot.new()
plt.choropleth(
locations: state_codes
z: population
locationmode: 'USA-states'
colorscale: 'Viridis'
)
plt.layout(
title: 'US Population by State'
geo: plot.Geo{
scope: 'usa'
}
)
plt.show()!
Parallel Coordinates (Multi-dimensional)
import vsl.plot
mut plt := plot.Plot.new()
plt.parcoords(
dimensions: [
plot.Dimension{
label: 'Feature 1'
values: [1.0, 2.0, 3.0, 4.0]
},
plot.Dimension{
label: 'Feature 2'
values: [10.0, 20.0, 30.0, 40.0]
},
]
)
plt.layout(title: 'Multi-dimensional Analysis')
plt.show()!
Bar Chart
import vsl.plot
categories := ['A', 'B', 'C', 'D']
values := [23.0, 45.0, 56.0, 78.0]
mut plt := plot.Plot.new()
plt.bar(x: categories, y: values)
plt.layout(title: 'Category Comparison')
plt.show()!
Heatmap
import vsl.plot
// 2D data matrix
z := [[1.0, 20.0, 30.0], [20.0, 1.0, 60.0], [30.0, 60.0, 1.0]]
mut plt := plot.Plot.new()
plt.heatmap(z: z)
plt.layout(title: 'Correlation Matrix')
plt.show()!
🎨 Customization Guide
Styling Options
Colors: Use hex codes (#FF0000
), RGB (rgb(255,0,0)
), or named colors (red
)
Markers: Control size, color, symbol, and opacity
marker:
plot.Marker
{
size: []f64{len: data.len, init: 12.0}
color: ['#FF0000', '#00FF00', '#0000FF']
symbol: 'circle' // Options: circle, square, diamond, triangle, etc.
}
Lines: Customize thickness, style, and color
line:
plot.Line
{
color: '#FF0000'
width: 3.0
dash: 'solid' // Options: solid, dash, dot, dashdot
}
Layout Configuration
plt.layout(
title: 'My Plot Title'
xaxis: plot.Axis{
title: plot.AxisTitle{text: 'X-axis Label'}
range: [0.0, 10.0] // Set axis range
}
yaxis: plot.Axis{
title: plot.AxisTitle{text: 'Y-axis Label'}
type: 'log' // Linear or logarithmic scale
}
width: 800
height: 600
)
🔧 Annotations & Text
Adding Annotations (Fixed Arrow Issue)
The most important fix for annotation arrows:
// ✅ CORRECT: No unwanted arrows
annotation := plot.Annotation{
text: 'Important Point'
x: 5.0
y: 25.0
showarrow: false // This prevents unwanted arrows!
font: plot.Font{
size: 14
color: '#000000'
}
}
plt.layout(
title: 'Plot with Clean Annotations'
annotations: [annotation]
)
Text Styling
font:
plot.Font
{
family: 'Arial, sans-serif'
size: 16
color: '#333333'
}
Arrow Customization
annotation := plot.Annotation
{
text: 'Point with Arrow'
x: 5.0
y: 10.0
showarrow: true
arrowhead: 2 // Arrow style (0-8)
arrowcolor: '#FF0000' // Red arrow color
}
🐛 Common Issues & Solutions
Annotation Arrows Appearing Unexpectedly
Problem: Unwanted arrows show up with annotations Solution: Always set showarrow: false
unless arrows are specifically needed
// ❌ WRONG: May show unwanted arrows
annotation := plot.Annotation{
text: 'My annotation'
x: 1.0
y: 2.0
// Missing showarrow property
}
// ✅ CORRECT: Clean text annotation
annotation := plot.Annotation{
text: 'My annotation'
x: 1.0
y: 2.0
showarrow: false // Explicitly prevent arrows
}
Plot Not Displaying
Common causes:
- Missing
plt.show()!
call - Browser not opening HTML file
- Invalid data format (ensure f64 for numeric data)
Performance Issues
Large datasets:
- Consider data sampling for >10,000 points
- Use appropriate plot types (heatmap for dense 2D data)
- Optimize marker sizes and line widths
📚 Advanced Examples
Multiple Data Series
mut plt := plot.Plot.new()
// First series
plt.scatter(
x: x1, y: y1
name: 'Dataset 1'
marker: plot.Marker{color: ['#FF0000']}
)
// Second series
plt.scatter(
x: x2, y: y2
name: 'Dataset 2'
marker: plot.Marker{color: ['#0000FF']}
)
Subplots (Coming Soon)
The VSL plot module is actively developed. Subplot functionality is planned for future releases.
Create beautiful, interactive visualizations with VSL Plot! 🚀
Based on Plotly's graph_objects API design.
fn Plot.new #
fn Plot.new() &Plot
type Trace #
type Trace = BarTrace
| BoxTrace
| CandlestickTrace
| ContourTrace
| FunnelTrace
| HeatmapTrace
| HistogramTrace
| LineTrace
| PieTrace
| Scatter3DTrace
| ScatterPolarTrace
| ScatterTrace
| SunburstTrace
| SurfaceTrace
| TreemapTrace
| ViolinTrace
| WaterfallTrace
| Histogram2DTrace
| DensityTrace
| RidgelineTrace
| ParallelCoordinatesTrace
| SankeyTrace
| ChordTrace
| NetworkTrace
| ChoroplethTrace
| ScatterMapboxTrace
| DensityMapboxTrace
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
line
box
violin
contour
waterfall
sunburst
treemap
candlestick
funnel
scatterpolar
histogram2d
density
ridgeline
parcoords
sankey
chord
network
choropleth
scattermapbox
densitymapbox
}
Enum for trace types
struct AngularAxis #
struct AngularAxis {
pub mut:
visible bool @[omitempty]
tickvals []f64 @[omitempty]
ticktext []string @[omitempty]
direction string @[omitempty] // 'clockwise' or 'counterclockwise'
period f64 @[omitempty]
rotation f64 @[omitempty]
showgrid bool @[omitempty]
gridcolor string @[omitempty]
linecolor string @[omitempty]
}
AngularAxis for polar plots
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]
showgrid bool @[omitempty]
tickangle f64 @[omitempty]
scaleanchor string @[omitempty]
rangeslider RangeSlider @[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 Box #
struct Box {
pub mut:
visible bool @[omitempty]
width f64 @[omitempty]
}
Box is a struct for box configuration in violin plots
struct BoxTrace #
struct BoxTrace {
CommonTrace
pub mut:
boxpoints string @[omitempty] // 'all', 'outliers', 'suspectedoutliers', false
boxmean string @[omitempty] // true, 'sd'
notched bool @[omitempty]
orientation string @[omitempty] // 'v' or 'h'
q1 []f64 @[omitempty]
median []f64 @[omitempty]
q3 []f64 @[omitempty]
lowerfence []f64 @[omitempty]
upperfence []f64 @[omitempty]
}
BoxTrace is a struct for Box trace type
struct CandlestickTrace #
struct CandlestickTrace {
CommonTrace
pub mut:
open []f64 @[omitempty]
high []f64 @[omitempty]
low []f64 @[omitempty]
close []f64 @[omitempty]
increasing Increasing @[omitempty]
decreasing Decreasing @[omitempty]
xperiod string @[omitempty]
xperiodalignment string @[omitempty]
}
CandlestickTrace is a struct for Candlestick trace type
struct ChordTrace #
struct ChordTrace {
CommonTrace
pub mut:
matrix [][]f64 @[omitempty]
labels []string @[omitempty]
rotation f64 @[omitempty]
sort string @[omitempty] // 'ascending', 'descending', 'none'
thickness f64 @[omitempty]
}
ChordTrace is a struct for Chord diagram trace type
struct ChoroplethTrace #
struct ChoroplethTrace {
CommonTrace
pub mut:
locations []string @[omitempty]
geojson string @[omitempty]
featureidkey string @[omitempty]
locationmode string @[omitempty] // 'ISO-3', 'USA-states', 'country names', 'geojson-id'
reversescale bool @[omitempty]
showscale bool @[omitempty]
hovertemplate string @[omitempty]
}
ChoroplethTrace is a struct for Choropleth map trace type
struct Cluster #
struct Cluster {
pub mut:
enabled bool @[omitempty]
color []string @[omitempty]
size []f64 @[omitempty]
opacity f64 @[omitempty]
step f64 @[omitempty]
maxzoom int @[omitempty]
}
Cluster is a struct for mapbox clustering
struct CommonTrace #
struct CommonTrace {
pub mut:
x XType
x0 string @[omitempty] // Single x position for violin/box plots
xbins map[string]f32
y YType @[omitempty]
y0 string @[omitempty] // Single y position for horizontal plots
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 Connector #
struct Connector {
pub mut:
visible bool @[omitempty]
line Line @[omitempty]
mode string @[omitempty] // 'spanning', 'between'
}
Connector is a struct for waterfall and funnel connectors
struct ContourTrace #
struct ContourTrace {
CommonTrace
pub mut:
contours Contours @[omitempty]
hovertemplate string @[omitempty]
autocontour bool @[omitempty]
ncontours int @[omitempty]
}
ContourTrace is a struct for Contour trace type
struct Contours #
struct Contours {
pub mut:
start f64 @[omitempty]
end f64 @[omitempty]
size f64 @[omitempty]
coloring string @[omitempty] // 'fill', 'heatmap', 'lines', 'none'
showlines bool @[omitempty]
showlabels bool @[omitempty]
}
Contours is a struct for contour configuration
struct Decreasing #
struct Decreasing {
pub mut:
marker Marker @[omitempty]
line Line @[omitempty]
}
Decreasing is a struct for decreasing values styling
struct DensityMapboxTrace #
struct DensityMapboxTrace {
CommonTrace
pub mut:
lat []f64 @[omitempty]
lon []f64 @[omitempty]
radius []f64 @[omitempty]
opacity f64 @[omitempty]
reversescale bool @[omitempty]
showscale bool @[omitempty]
subplot string @[omitempty]
}
DensityMapboxTrace is a struct for Density on mapbox trace type
struct DensityTrace #
struct DensityTrace {
CommonTrace
pub mut:
bandwidth f64 @[omitempty]
showscale bool @[omitempty]
reversescale bool @[omitempty]
contours Contours @[omitempty]
}
DensityTrace is a struct for Density plot trace type
struct Dimension #
struct Dimension {
pub mut:
label string @[omitempty]
values []f64 @[omitempty]
range []f64 @[omitempty]
constraintrange [][]f64 @[omitempty]
tickvals []f64 @[omitempty]
ticktext []string @[omitempty]
visible bool @[omitempty]
multiselect bool @[omitempty]
}
Dimension is a struct for parallel coordinates dimensions
struct Font #
struct Font {
pub mut:
color string = 'black'
family string = 'monospace'
size f64 = 16.0
}
Font handles data to customize fonts
struct FunnelTrace #
struct FunnelTrace {
CommonTrace
pub mut:
values []f64 @[omitempty]
orientation string @[omitempty] // 'v' or 'h'
connector Connector @[omitempty]
}
FunnelTrace is a struct for Funnel trace type
struct Geo #
struct Geo {
pub mut:
scope string @[omitempty] // 'world', 'usa', 'europe', 'asia', 'africa', 'north america', 'south america'
projection GeoProjection @[omitempty]
showland bool @[omitempty]
landcolor string @[omitempty]
showocean bool @[omitempty]
oceancolor string @[omitempty]
showlakes bool @[omitempty]
lakecolor string @[omitempty]
showcountries bool @[omitempty]
countrycolor string @[omitempty]
showsubunits bool @[omitempty]
subunitcolor string @[omitempty]
resolution string @[omitempty] // '110', '50', '10'
bgcolor string @[omitempty]
}
Geo layout for geographic plots
struct GeoCenter #
struct GeoCenter {
pub mut:
lon f64 @[omitempty]
lat f64 @[omitempty]
}
GeoCenter for geographic center
struct GeoProjection #
struct GeoProjection {
pub mut:
typ string @[omitempty] // 'albers usa', 'mercator', 'orthographic', 'natural earth', etc.
rotation GeoRotation @[omitempty]
scale f64 @[omitempty]
center GeoCenter @[omitempty]
}
GeoProjection for geographic projections
struct GeoRotation #
struct GeoRotation {
pub mut:
lon f64 @[omitempty]
lat f64 @[omitempty]
roll f64 @[omitempty]
}
GeoRotation for geographic rotation
struct HeatmapTrace #
struct HeatmapTrace {
CommonTrace
pub mut:
hovertemplate string @[omitempty]
zsmooth string @[omitempty]
}
HeatmapTrace is a struct for Heatmap trace type
struct Histogram2DTrace #
struct Histogram2DTrace {
CommonTrace
pub mut:
nbinsx int @[omitempty]
nbinsy int @[omitempty]
autobinx bool @[omitempty]
autobiny bool @[omitempty]
xbins Bins @[omitempty]
ybins Bins @[omitempty]
histfunc string @[omitempty] // 'count', 'sum', 'avg', 'min', 'max'
histnorm string @[omitempty] // '', 'percent', 'probability', 'density', 'probability density'
showscale bool @[omitempty]
reversescale bool @[omitempty]
}
Histogram2DTrace is a struct for 2D Histogram 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 Increasing #
struct Increasing {
pub mut:
marker Marker @[omitempty]
line Line @[omitempty]
}
Increasing is a struct for increasing values styling
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
showlegend bool @[omitempty]
plot_bgcolor string @[omitempty]
paper_bgcolor string @[omitempty]
polar Polar @[omitempty]
geo Geo @[omitempty] // For geographic plots
mapbox Mapbox @[omitempty] // For mapbox plots
}
Layout
struct Light #
struct Light {
pub mut:
azimuth f64 @[omitempty]
elevation f64 @[omitempty]
intensity f64 @[omitempty]
color []f64 @[omitempty]
}
Light for mapbox plots
struct Line #
struct Line {
pub mut:
color string @[omitempty]
width f64 = 2.0 @[omitempty]
dash string = 'solid' @[omitempty]
visible bool @[omitempty]
}
Line is a struct for line properties in a trace
struct LineTrace #
struct LineTrace {
CommonTrace
pub mut:
connectgaps bool @[omitempty]
}
LineTrace is a struct for Line trace type
struct Mapbox #
struct Mapbox {
pub mut:
style string @[omitempty] // 'open-street-map', 'carto-positron', 'carto-darkmatter', 'stamen-terrain', etc.
center MapboxCenter @[omitempty]
zoom f64 @[omitempty]
bearing f64 @[omitempty]
pitch f64 @[omitempty]
accesstoken string @[omitempty]
}
Mapbox layout for mapbox plots
struct MapboxCenter #
struct MapboxCenter {
pub mut:
lat f64 @[omitempty]
lon f64 @[omitempty]
}
MapboxCenter for mapbox center
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 NetworkEdges #
struct NetworkEdges {
pub mut:
x []f64 @[omitempty]
y []f64 @[omitempty]
line Line @[omitempty]
hoverinfo string @[omitempty]
mode string @[omitempty]
}
NetworkEdges is a struct for network graph edges
struct NetworkNodes #
struct NetworkNodes {
pub mut:
x []f64 @[omitempty]
y []f64 @[omitempty]
text []string @[omitempty]
ids []string @[omitempty]
values []f64 @[omitempty]
labels []string @[omitempty]
marker Marker @[omitempty]
line Line @[omitempty]
hoverinfo string @[omitempty]
}
NetworkNodes is a struct for network graph nodes
struct NetworkTrace #
struct NetworkTrace {
CommonTrace
pub mut:
nodes NetworkNodes @[omitempty]
edges NetworkEdges @[omitempty]
layout string @[omitempty] // 'force', 'circle', 'tree', 'random'
iterations int @[omitempty]
node_trace bool @[omitempty]
edge_trace bool @[omitempty]
}
NetworkTrace is a struct for Network/Graph trace type
struct ParallelCoordinatesTrace #
struct ParallelCoordinatesTrace {
pub mut:
dimensions []Dimension @[omitempty]
line ParallelLine @[omitempty]
name string @[omitempty]
labelangle f64 @[omitempty]
labelside string @[omitempty] // 'top', 'bottom'
}
ParallelCoordinatesTrace is a struct for Parallel Coordinates trace type
struct ParallelLine #
struct ParallelLine {
pub mut:
color []f64 @[omitempty]
colorscale string @[omitempty]
showscale bool @[omitempty]
reversescale bool @[omitempty]
cmin f64 @[omitempty]
cmax f64 @[omitempty]
cmid f64 @[omitempty]
}
ParallelLine is a struct for parallel coordinates line styling
struct PathBar #
struct PathBar {
pub mut:
visible bool @[omitempty]
side string @[omitempty] // 'top', 'bottom'
edgeshape string @[omitempty] // 'rounded', 'sharp'
thickness int @[omitempty]
}
PathBar is a struct for treemap pathbar configuration
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) box #
fn (mut p Plot) box(trace BoxTrace) Plot
box adds a box trace to the plot
fn (Plot) candlestick #
fn (mut p Plot) candlestick(trace CandlestickTrace) Plot
candlestick adds a candlestick trace to the plot
fn (Plot) chord #
fn (mut p Plot) chord(trace ChordTrace) Plot
chord adds a chord diagram trace to the plot
fn (Plot) choropleth #
fn (mut p Plot) choropleth(trace ChoroplethTrace) Plot
choropleth adds a choropleth map trace to the plot
fn (Plot) contour #
fn (mut p Plot) contour(trace ContourTrace) Plot
contour adds a contour trace to the plot
fn (Plot) debug_json #
fn (p Plot) debug_json()
debug_json prints the JSON that would be sent to Plotly.js for debugging
fn (Plot) density #
fn (mut p Plot) density(trace DensityTrace) Plot
density adds a density plot trace to the plot
fn (Plot) densitymapbox #
fn (mut p Plot) densitymapbox(trace DensityMapboxTrace) Plot
densitymapbox adds a density on mapbox trace to the plot
fn (Plot) funnel #
fn (mut p Plot) funnel(trace FunnelTrace) Plot
funnel adds a funnel 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) histogram2d #
fn (mut p Plot) histogram2d(trace Histogram2DTrace) Plot
histogram2d adds a 2D 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) layout_json #
fn (p Plot) layout_json() string
layout_json returns the layout configuration as a JSON string The returned JSON is compatible with Plotly.js format
fn (Plot) line #
fn (mut p Plot) line(trace LineTrace) Plot
line adds a line trace to the plot
fn (Plot) network #
fn (mut p Plot) network(trace NetworkTrace) Plot
network adds a network/graph trace to the plot
fn (Plot) parcoords #
fn (mut p Plot) parcoords(trace ParallelCoordinatesTrace) Plot
parcoords adds a parallel coordinates trace to the plot
fn (Plot) pie #
fn (mut p Plot) pie(trace PieTrace) Plot
pie adds a pie trace to the plot
fn (Plot) ridgeline #
fn (mut p Plot) ridgeline(trace RidgelineTrace) Plot
ridgeline adds a ridgeline plot trace to the plot
fn (Plot) sankey #
fn (mut p Plot) sankey(trace SankeyTrace) Plot
sankey adds a Sankey diagram 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) scattermapbox #
fn (mut p Plot) scattermapbox(trace ScatterMapboxTrace) Plot
scattermapbox adds a scatter on mapbox trace to the plot
fn (Plot) scatterpolar #
fn (mut p Plot) scatterpolar(trace ScatterPolarTrace) Plot
scatterpolar adds a polar/radar trace to the plot
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) sunburst #
fn (mut p Plot) sunburst(trace SunburstTrace) Plot
sunburst adds a sunburst trace to the plot
fn (Plot) surface #
fn (mut p Plot) surface(trace SurfaceTrace) Plot
surface adds a surface trace to the plot
fn (Plot) to_json #
fn (p Plot) to_json() (string, string)
to_json returns the plot's traces and layout as separate JSON strings This method provides flexibility for embedding plots in custom web pages or using the plot data in other contexts
fn (Plot) traces_json #
fn (p Plot) traces_json() string
traces_json returns the traces data as a JSON string The returned JSON is compatible with Plotly.js format
fn (Plot) treemap #
fn (mut p Plot) treemap(trace TreemapTrace) Plot
treemap adds a treemap trace to the plot
fn (Plot) violin #
fn (mut p Plot) violin(trace ViolinTrace) Plot
violin adds a violin trace to the plot
fn (Plot) waterfall #
fn (mut p Plot) waterfall(trace WaterfallTrace) Plot
waterfall adds a waterfall 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 Polar #
struct Polar {
pub mut:
radialaxis RadialAxis @[omitempty]
angularaxis AngularAxis @[omitempty]
sector []f64 @[omitempty]
hole f64 @[omitempty]
bgcolor string @[omitempty]
}
Polar layout for radar/polar charts
struct RadialAxis #
struct RadialAxis {
pub mut:
visible bool @[omitempty]
range []f64 @[omitempty]
tickvals []f64 @[omitempty]
ticktext []string @[omitempty]
tickangle f64 @[omitempty]
showgrid bool @[omitempty]
gridcolor string @[omitempty]
linecolor string @[omitempty]
}
RadialAxis for polar plots
struct RangeSlider #
struct RangeSlider {
pub mut:
visible bool @[omitempty]
range []f64 @[omitempty]
thickness f64 @[omitempty]
}
RangeSlider handles range slider configuration for axes
struct RidgelineTrace #
struct RidgelineTrace {
CommonTrace
pub mut:
orientation string @[omitempty] // 'v' or 'h'
bandwidth f64 @[omitempty]
scale f64 @[omitempty] // Scaling factor for ridge height
overlap f64 @[omitempty] // Overlap between ridges
}
RidgelineTrace is a struct for Ridgeline plot trace type
struct SankeyLink #
struct SankeyLink {
pub mut:
source []int @[omitempty]
target []int @[omitempty]
value []f64 @[omitempty]
label []string @[omitempty]
color []string @[omitempty]
line Line @[omitempty]
hovertemplate string @[omitempty]
}
SankeyLink is a struct for Sankey diagram links
struct SankeyNode #
struct SankeyNode {
pub mut:
label []string @[omitempty]
color []string @[omitempty]
line Line @[omitempty]
thickness f64 @[omitempty]
pad f64 @[omitempty]
x []f64 @[omitempty]
y []f64 @[omitempty]
groups [][]int @[omitempty]
}
SankeyNode is a struct for Sankey diagram nodes
struct SankeyTrace #
struct SankeyTrace {
pub mut:
node SankeyNode @[omitempty]
link SankeyLink @[omitempty]
orientation string @[omitempty] // 'v' or 'h'
valueformat string @[omitempty]
valuesuffix string @[omitempty]
name string @[omitempty]
}
SankeyTrace is a struct for Sankey diagram trace type
struct Scatter3DTrace #
struct Scatter3DTrace {
CommonTrace
}
Scatter3DTrace is a struct for Scatter3D trace type
struct ScatterMapboxTrace #
struct ScatterMapboxTrace {
CommonTrace
pub mut:
lat []f64 @[omitempty]
lon []f64 @[omitempty]
mode string @[omitempty] // 'markers', 'lines', 'lines+markers'
cluster Cluster @[omitempty]
hovertemplate string @[omitempty]
subplot string @[omitempty]
}
ScatterMapboxTrace is a struct for Scatter on mapbox trace type
struct ScatterPolarTrace #
struct ScatterPolarTrace {
CommonTrace
pub mut:
r []f64 @[omitempty]
theta []f64 @[omitempty]
thetaunit string @[omitempty] // 'radians', 'degrees'
subplot string @[omitempty]
}
ScatterPolarTrace is a struct for Radar/Polar trace type
struct ScatterTrace #
struct ScatterTrace {
CommonTrace
}
ScatterTrace is a struct for Scatter trace type
struct SunburstTrace #
struct SunburstTrace {
CommonTrace
pub mut:
labels []string @[omitempty]
parents []string @[omitempty]
values []f64 @[omitempty]
branchvalues string @[omitempty] // 'total', 'remainder'
count string @[omitempty]
ids []string @[omitempty]
level string @[omitempty]
maxdepth int @[omitempty]
}
SunburstTrace is a struct for Sunburst trace type
struct SurfaceTrace #
struct SurfaceTrace {
CommonTrace
pub mut:
hovertemplate string @[omitempty]
}
SurfaceTrace is a struct for Surface trace type
struct Totals #
struct Totals {
pub mut:
marker Marker @[omitempty]
line Line @[omitempty]
}
Totals is a struct for totals styling in waterfall charts
struct TreemapTrace #
struct TreemapTrace {
CommonTrace
pub mut:
labels []string @[omitempty]
parents []string @[omitempty]
values []f64 @[omitempty]
branchvalues string @[omitempty] // 'total', 'remainder'
count string @[omitempty]
ids []string @[omitempty]
level string @[omitempty]
maxdepth int @[omitempty]
pathbar PathBar @[omitempty]
}
TreemapTrace is a struct for Treemap trace type
struct ViolinTrace #
struct ViolinTrace {
pub mut:
// Core violin fields
x []string @[omitempty] // For grouped violin plots
y YType @[omitempty]
x0 string @[omitempty] // Single x position for violin plots
name string @[omitempty]
marker Marker @[omitempty]
line Line @[omitempty]
colorscale string = 'Viridis' @[omitempty]
fillcolor string @[omitempty] // Fill color for violin
opacity f64 @[omitempty] // Opacity for violin
// Violin-specific fields
side string @[omitempty] // 'both', 'positive', 'negative'
bandwidth f64 @[omitempty]
orientation string @[omitempty] // 'v' or 'h'
points string @[omitempty] // 'all', 'outliers', 'suspectedoutliers', false
box Box @[omitempty]
meanline Line @[omitempty]
}
ViolinTrace is a struct for Violin trace type
struct WaterfallTrace #
struct WaterfallTrace {
CommonTrace
pub mut:
measure []string @[omitempty] // 'relative', 'total', 'absolute'
base f64 @[omitempty]
orientation string @[omitempty] // 'v' or 'h'
connector Connector @[omitempty]
decreasing Decreasing @[omitempty]
increasing Increasing @[omitempty]
totals Totals @[omitempty]
}
WaterfallTrace is a struct for Waterfall trace type
- README
- fn Plot.new
- type Trace
- type XType
- type YType
- type ZType
- enum TraceType
- struct AngularAxis
- struct Annotation
- struct Axis
- struct AxisTitle
- struct BarTrace
- struct Bins
- struct Box
- struct BoxTrace
- struct CandlestickTrace
- struct ChordTrace
- struct ChoroplethTrace
- struct Cluster
- struct CommonTrace
- struct Connector
- struct ContourTrace
- struct Contours
- struct Decreasing
- struct DensityMapboxTrace
- struct DensityTrace
- struct Dimension
- struct Font
- struct FunnelTrace
- struct Geo
- struct GeoCenter
- struct GeoProjection
- struct GeoRotation
- struct HeatmapTrace
- struct Histogram2DTrace
- struct HistogramTrace
- struct Increasing
- struct Layout
- struct Light
- struct Line
- struct LineTrace
- struct Mapbox
- struct MapboxCenter
- struct Marker
- struct NetworkEdges
- struct NetworkNodes
- struct NetworkTrace
- struct ParallelCoordinatesTrace
- struct ParallelLine
- struct PathBar
- struct PieTrace
- struct Plot
- fn annotation
- fn bar
- fn box
- fn candlestick
- fn chord
- fn choropleth
- fn contour
- fn debug_json
- fn density
- fn densitymapbox
- fn funnel
- fn get_plotly_script
- fn heatmap
- fn histogram
- fn histogram2d
- fn layout
- fn layout_json
- fn line
- fn network
- fn parcoords
- fn pie
- fn ridgeline
- fn sankey
- fn scatter
- fn scatter3d
- fn scattermapbox
- fn scatterpolar
- fn show
- fn sunburst
- fn surface
- fn to_json
- fn traces_json
- fn treemap
- fn violin
- fn waterfall
- struct PlotConfig
- struct PlotlyScriptConfig
- struct Polar
- struct RadialAxis
- struct RangeSlider
- struct RidgelineTrace
- struct SankeyLink
- struct SankeyNode
- struct SankeyTrace
- struct Scatter3DTrace
- struct ScatterMapboxTrace
- struct ScatterPolarTrace
- struct ScatterTrace
- struct SunburstTrace
- struct SurfaceTrace
- struct Totals
- struct TreemapTrace
- struct ViolinTrace
- struct WaterfallTrace