Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vplot

A V wrapper for gnuplot: plot functions, data series, and 3D surfaces through a persistent gnuplot process driven over its stdin pipe.

Requirements

  • V 0.4+
  • gnuplot on PATH (or set VPLOT_GNUPLOT to the binary)

Install

v install --git https://github.com/<you>/vplot

or clone and use as a local module / symlink into ~/.vmodules.

Usage

module main

import vplot

fn main() {
	mut p := vplot.new() or { panic(err) } // headless: no GUI window
	defer { p.close() }

	p.set_title('Demo') or { panic(err) }
	p.set_grid(true) or { panic(err) }

	// plot functions
	p.plot_fns(['sin(x)', 'cos(x)'], samples: 500) or { panic(err) }

	// or plot data series
	x := [0.0, 1, 2, 3, 4]
	y := [0.0, 1, 4, 9, 16]
	p.plot_xy(x, y, label: 'x^2', style: .lines_points, color: '#d62728') or { panic(err) }

	// export (terminal inferred from extension)
	p.save('plot.png', 900, 600) or { panic(err) } // also: .svg .pdf .eps .txt
}

new() is headless by default (it selects gnuplot's no-op unknown terminal), so nothing ever pops up and save() still works — ideal for scripts, CI, and SSH sessions. Pass vplot.new(interactive: true) if you want live GUI plot windows, or call p.set_terminal('qt') at any time.

See examples/ for multi-series data plots (data.v) and 3D surfaces (surface.v). Run one with:

v -path '@vlib|.' run examples/basic/basic.v

API overview

Function Purpose
new() ! spawn persistent gnuplot process (headless; new(interactive: true) for GUI windows)
cmd(string) ! send any raw gnuplot command
plot_fn(expr, cfg) / plot_fns(exprs, cfg) function plots
plot_xy(x, y, cfg) / plot_series([]Series) data plots
plot3_fn(expr, label) 3D surface
save(path, w, h) export via replot (.png/.svg/.pdf/.eps/.txt)
set_title/xlabel/ylabel/xrange/yrange/grid/log_y styling
set_terminal(term) switch gnuplot terminal at runtime
close() quit gnuplot, clean up temp files

Set p.debug = true to echo every gnuplot command to stderr.

Tests

v test .

Tests skip automatically when gnuplot is not installed.

About

V wrapper for GNU Plot

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages