nuplot

Version, currently master branch1 version
  • master branchlatestMar 17, 2018

github.com/kojix2/nuplot

Running Gnuplot with Crystal.

7 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  nuplot:
    github: kojix2/nuplot
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.24.1
License
MIT
Author
kojix2 <kojix2@users.noreply.github.com>

Dependencies

This version declares no dependencies.

README

# nuplot

This is a minimum tool for running Gnuplot with Crystal. 

## Installation

Add this to your application's `shard.yml`:

```yaml
dependencies:
  nuplot:
    github: kojix2/nuplot
```

## Usage

```crystal
require "nuplot"
```
![sin(x)](https://raw.githubusercontent.com/kojix2/nuplot/master/img/sin.png)
```crystal
Gnuplot.plot do |s|
  s << "plot sin(x)"
end
```
![scatter plot](https://raw.githubusercontent.com/kojix2/nuplot/master/img/scatter2d.png)
```crystal
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](https://raw.githubusercontent.com/kojix2/nuplot/master/img/lines.png)
```crystal
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](https://raw.githubusercontent.com/kojix2/nuplot/master/img/scatter3d.png)
```crystal
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.