Sha256: abe7c2246b20baf4b26a66a45f0f2553449e8925edf11ce219004dcecb420d5d

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

$:.unshift(File.dirname(__FILE__)+"/../lib")
require 'rubyvis'
data = pv.range(100).map {|x| 
  OpenStruct.new({x: x, y: rand(), z: 10**(2*rand)})
}


w = 400
h = 400

x = pv.Scale.linear(0, 99).range(0, w)
y = pv.Scale.linear(0, 1).range(0, h)

c = pv.Scale.log(1, 100).range("orange", "brown")

# The root panel.
vis = pv.Panel.new()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(10)
    .top(5);

# Y-axis and ticks. 
vis.add(pv.Rule)
    .data(y.ticks())
    .bottom(y)
    .strokeStyle(lambda {|d| d!=0 ? "#eee" : "#000"})
  .anchor("left").add(pv.Label)
  .visible(lambda {|d|  d > 0 and d < 1})
  .text(y.tick_format)

# X-axis and ticks. 
vis.add(pv.Rule)
    .data(x.ticks())
    .left(x)
    .stroke_style(lambda {|d| d!=0 ? "#eee" : "#000"})
  .anchor("bottom").add(pv.Label)
  .visible(lambda {|d|  d > 0 and d < 100})
  .text(x.tick_format);

#/* The dot plot! */
vis.add(pv.Panel)
    .data(data)
  .add(pv.Dot)
  .left(lambda {|d| x.scale(d.x)})
  .bottom(lambda {|d| y.scale(d.y)})
  .stroke_style(lambda {|d| c.scale(d.z)})
  .fill_style(lambda {|d| c.scale(d.z).alpha(0.2)})
  .shape_size(lambda {|d| d.z})
  .title(lambda {|d| "%0.1f" % d.z})

vis.render()
puts vis.to_svg

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubyvis-0.1.5 examples/scatterplot.rb