gnu-plot

0.3.1 • Public • Published

node-gnuplot

javascript node.js wrapper for gnuplot

example

var gnuplot = require('gnu-plot')
gnuplot().plot([{
    data:[[0,0],[1,1],[2,0]]
}])

Breaking changes

Note: gnuplot.exe >=v5.4 mangles stdin on my Windows machine, I recommend staying on 5.2.8

Version 0.3.0

  • plotsSettings.color renamed to plotsSettings.rgbcolor
    Fix : color:"#FF0000" -> rgbcolor:"#FF0000"

Methods

gnuplot()

Spawn a new gnuplot process and return a plot object inheriting child_process.

var plot = gnuplot()

plot.plot(plotsSettings)

Plots with plotsSettings Array.

plotsSettings

Array of plot settings objects corresponding to different data series

[{
	title:<title>,

	using:<using>,
	smooth:<smooth>,
	axes:<axes>,
	bin:<using>,

	style:<style>,
	color:<color>,
	rgbcolor:<rgbcolor>,

	data:<data>,
},...]

title

default: <index of setting object in plotsSettings array>
Title of the data serie

using

default: undefined
Used to tell gnuplot which data columns (or pseudo-column to use). Please refer to gnuplot documentation.
Can be used to handle datetime data or change missing data handling.

smooth

default: undefined
Used for interpolation and approximation of data. Please refer to gnuplot documentation.

axes

default: x1y1
Axes used for the data serie.
Choose from ["x1y1","x1y2","x2y1","x2y2"]
The axes are positionned :
- x1: bottom
- x2: top
- y1: left
- y2: right

bin

default: undefined
Used to bin data. Please refer to gnuplot documentation.
You should calculate them in JS instead of with gnuplot.

style

default: "lines"
Style of the data serie in :

lines
points
linespoints
surface
dots
impulse
boxes

see with clause of the plot command in gnuplot documentation for more.

color

shorthand for style:"linecolor <color>"
Color setting of the data serie
Used with

rgbcolor

shorthand for style:"linecolor rgbcolor \"<color>\""
Color of the data serie
by name : execute gnuplot -e "show colornames" to view all possible values
by value : #RRGGBB, #AARRGGBB

data

Data Array with structure

[[x0,y0],[x1,y1],[x2,y2], ...]

Or mathematical formula

"2*x**2+3*x+4"

Example

plot.plot([{
	title:"A",
	rgbcolor:"#00FF00",
	data:[
		[0  , 10],
		[0.5, 90],
		[1  , 85],
		[1.5, 20],
		[2  , 25]
	]
},{
	title:"B",
	rgbcolor:"red",
	style:"linespoints",
	data:[
		[0.4,30],
		[1.1,70],
		[1.8,40]
	],
},{
	title:"C",
	rgbcolor:"blue",
	data: "-2*x**2+3*x+4",
}])

plot.splot(plotsSettings)

Same as plot.plot(plotsSettings) for 3D plots

plot.set(options)

Set or unset some gnuplot options.

options

Object containing options as key:values.
See gnuplot documentation for a complete list of available options.

Notable options:

Axes label

{x|y|x2|y2|z}label:<label>

plot.set({xlabel:"'s'",yrange:"'°C'"})

Fixed axes

{x|y|x2|y2}range:"[[<min>]:[<max>]]"

plot.set({xrange:"[0:]",yrange:"[-5:5]"})

Line at origin

{x|y|x2|y2|z}zeroaxis: true

plot.set({yzeroaxis:true})

Axes tics interval

{x|mx|y|my|x2|mx2|y2|my2|z|mz}tics:<interval>

plot.set({
	xtics: 10,      // major xtic every 10
	mxtics: 2,      // 2 minor xtics per major xtic
	ytics: [
		10,         // major ytic every 10
		"add (42)", // add ytic at y=42
	],
	y2tics: true,   // show auto interval tics
})

Log scale

logscale:"[x][x2][y][y2][z] <base>"
default base : 10

plot.set({
	logscale:[
		"x",     // logscale for x axis with default base 10
		"yy2 2", // logscale for y and y2 axes with base 2
	],
})

Grid

grid: "[xtics] [mxtics] [ytics] [mytics] [ztics] [mztics] [<style>]"

plot.set({grid:"xtics ytics"})// default style
plot.set({grid:"xtics mxtics ytics mytics lines -1 dashtype 2, lines 0"}) // dashed for tics, dotted for minor tics

output to image

term:"{png|jpeg} size <x>,<y>", output:"<file>"

plot.set({term:"png size 800,600", output:"plot.png"})

output to terminal

term:"dumb [size <x> <y>]"

plot.stdout.pipe(process.stdout) //print gnuplot output to console
// plot 200 characters wide & 50 chararcters tall 
plot.set({term:"dumb 200 50"})
// or for a plot filling the terminal
plot.set({term:"dumb "+process.stdout.columns+" "+process.stdout.rows})

plot.print(string)

Write string to stdin of the gnuplot process.

Readme

Keywords

Package Sidebar

Install

npm i gnu-plot

Weekly Downloads

55

Version

0.3.1

License

none

Unpacked Size

1.91 MB

Total Files

5

Last publish

Collaborators

  • v1rgul