1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
module UnicodePlot
class Scatterplot < GridPlot
end
module_function def scatterplot(*args,
canvas: :braille,
color: :auto,
name: "",
**kw)
case args.length
when 1
# y only
y = Array(args[0])
x = Array(1 .. y.length)
when 2
# x and y
x = Array(args[0])
y = Array(args[1])
else
raise ArgumentError, "worng number of arguments"
end
plot = Scatterplot.new(x, y, canvas, **kw)
scatterplot!(plot, x, y, color: color, name: name)
end
module_function def scatterplot!(plot,
*args,
color: :auto,
name: "")
case args.length
when 1
# y only
y = Array(args[0])
x = Array(1 .. y.length)
when 2
# x and y
x = Array(args[0])
y = Array(args[1])
else
raise ArgumentError, "worng number of arguments"
end
color = color == :auto ? plot.next_color : color
plot.annotate!(:r, name.to_s, color: color) unless name.nil? || name == ""
plot.points!(x, y, color)
plot
end
end
|