nuplot

This is a minimum tool for running Gnuplot with Crystal.

Installation

Add this to your application's shard.yml:

dependencies:
  nuplot:
    github: kojix2/nuplot

Usage

require "nuplot"

sin(x)

Gnuplot.plot do |s|
  s << "plot sin(x)"
end

scatter plot

x = Array(Float64).new(100){ rand(10.0..20.0) }
y = Array(Float64).new(100){ rand(100.0..200.0) }

Gnuplot.plot do |s|
  s << "set title 'SCATTER'"
  s << "plot '-' pt 6 lt rgb 'red' t 'circle'"
  s << to_gp([x, y])
end

lines plot

memo = 0
x = Array(Float64).new(100,0.0)

# Optimistic random walk
100.times do |i|
  memo = memo + rand(-0.9..1.0)
  x[i] = memo
end

Gnuplot.plot do |s|
  s << "set title 'LINES'"
  s << "plot '-' with lines title 'x'"
  s << to_gp(x)
end

scatter plot 3d

x = Array(Float64).new(1000){ rand(-10.0..10.0) }
y = Array(Float64).new(1000){ rand(-10.0..10.0) }
z = Array(Float64).new(1000){ |i| x[i]**2 + y[i]**2 }

Gnuplot.plot do |s|
  s << "set title 'SCATTER 3D'"
  s << "splot '-' pt 6 t 'z=x^2+y^2'"
  s << to_gp([x,y,z])
end

Development

What I do not do

Contributing

Pull requests are always welcome.