In [1]:
require 'nyaplot'


Out[1]:
true

In [2]:
include Nyaplot


Out[2]:
Object

In [3]:
Nyaplot.set_url "http://nbviewer.ipython.org/github/domitry/nyaplot-notebooks/blob/master/Nyaplot1.0.0.ipynb"


Out[3]:
"http://nbviewer.ipython.org/github/domitry/nyaplot-notebooks/blob/master/Nyaplot1.0.0.ipynb"

New API


In [4]:
df = {x: [:a, :b, :c], y: [10, 20, 30]}
p = Plot.from(df).bar(x: :x, y: :y).title("Bar chart")


Out[4]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.

In [5]:
p.export_html("./plot.html")


Out[5]:
"Plot was saved to /home/naoki/ipynb/plot.html"

to_png


In [6]:
p.to_png



In [7]:
Colors.Pastel1


Out[7]:
rgb(251,180,174)rgb(179,205,227)rgb(204,235,197)rgb(222,203,228)rgb(254,217,166)rgb(255,255,204)rgb(229,216,189)rgb(253,218,236)rgb(242,242,242)
         

In [8]:
cs = Colors.Pastel1.to_a[0..2]


Out[8]:
["rgb(251,180,174)", "rgb(179,205,227)", "rgb(204,235,197)"]

In [9]:
df = {x: [:a, :b, :c], y: [10, 20, 30]}
p = Plot.from(df).bar(x: :x, y: :y, fill_by: :x, colors: cs)


Out[9]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.

In [10]:
p.to_png


Flexible size


In [11]:
x = []; y = []; theta = 0.85; a=1
while theta < 14*Math::PI do
  x.push(a*Math::cos(theta)/theta)
  y.push(a*Math::sin(theta)/theta)
  theta += 0.1
end

p = Plot.from({x: x, y: y}).line(x: :x, y: :y)


Out[11]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.

In [12]:
Plot.from({x: x, y: y}, width: 300, height: 300).line(x: :x, y: :y).to_png



In [13]:
p = Plot.from({x: x, y: y}, width: 150, height: 150).line(x: :x, y: :y)
p.xaxis.ticks(5)
p.yaxis.ticks(5)
p.to_png


Change style


In [14]:
def my_style(p)
    p.background.color("#fff")
    p.background.stroke_color("none")
    p.grid.color("#aaa")
    p.grid.dashed(true)
    p
end


Out[14]:
:my_style

In [15]:
p = my_style Plot.from({x: x, y: y}, width: 300, height: 300).line(x: :x, y: :y)


Out[15]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.

In [16]:
x = (1..100).to_a.map{|v| v.to_f/10}
y = x.map{|x| Math.exp(x)}
p = Plot.from({x: x, y: y}, x: :x, y: :y).line


Out[16]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.

In [17]:
p.yscale(:log)


Out[17]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.

In [18]:
p.yscale(:pow)


Out[18]:
Inline JavaScript is disabled for some reason. Use nbviewer to see plots.