nuplot

Running Gnuplot with Crystal.

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

  • Replacing the gnuplot idiom with a new Crystal object.

Contributing

  • bird1079s

Pull requests are always welcome.

Repository

nuplot

Owner
Statistic
  • 6
  • 1
  • 0
  • 0
  • 0
  • almost 7 years ago
  • February 10, 2018
License

MIT License

Links
Synced at

Mon, 23 Dec 2024 07:28:11 GMT

Languages