Notebook on nbviewer (original) (raw)

  1. sciruby-notebooks
  2. Visualization Notebook

Scatterplot with statsample

Creating a scatterplot with statsample's Statsample::Graph::Scatterplot class.

In this example we'll demonstrate how a normally distributed Daru::Vector can be created using the daru and distribution gems, and how the values generated can be plotted very easily using the 'scatterplot' shorthand and supplying X and Y co-ordinates.

Statsample uses rubyvis internally for generating plots.

In [1]:

require 'statsample' include Statsample::Shorthand

n = 100 x = rnorm(n) y = x + rnorm(n,0.5,0.2) Statsample::Graph::Scatterplot.new(x,y)

Out[1]:

−2.0 −1.5 −1.0 −0.5 0.5 1.0 1.5 2.0 2.5 3.0 0.5 1.0 1.5 2.0 2.5