In [1]:
require 'nyaplot'
Out[1]:
In [2]:
include Nyaplot
Out[2]:
In [3]:
Nyaplot.set_url "http://nbviewer.ipython.org/github/domitry/nyaplot-notebooks/blob/master/Nyaplot1.0.0.ipynb"
Out[3]:
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]:
In [5]:
p.export_html("./plot.html")
Out[5]:
In [6]:
p.to_png
In [7]:
Colors.Pastel1
Out[7]:
In [8]:
cs = Colors.Pastel1.to_a[0..2]
Out[8]:
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]:
In [10]:
p.to_png
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]:
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
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]:
In [15]:
p = my_style Plot.from({x: x, y: y}, width: 300, height: 300).line(x: :x, y: :y)
Out[15]:
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]:
In [17]:
p.yscale(:log)
Out[17]:
In [18]:
p.yscale(:pow)
Out[18]: