Add lineplot

This commit is contained in:
kojix2 2020-07-29 18:24:08 +09:00
parent e69d1caed7
commit 4a49711d57

View File

@ -29,6 +29,10 @@ module Uplot
case @ptype
when 'hist', 'histogram'
histogram(input_lines).render
when 'line', 'lineplot'
line(input_lines).render
when 'lines'
lines(input_lines).render
end
puts input_lines if @params[:p]
@ -38,5 +42,32 @@ module Uplot
series = input_lines.map(&:to_f)
UnicodePlot.histogram(series, nbins: @params[:nbins])
end
def line(input_lines)
x = []
y = []
input_lines.each_with_index do |l, i|
x[i], y[i] = l.split("\t")[0..1].map(&:to_f)
end
UnicodePlot.lineplot(x, y)
end
def lines(input_lines)
n_cols = input_lines[0].split("\t").size
cols = Array.new(n_cols){ [] }
input_lines.each_with_index do |row, i|
row.split("\t").each_with_index do |v, j|
cols[j][i] = v.to_f
end
end
require 'numo/narray'
pp Numo::DFloat.cast(cols)
plot = UnicodePlot.lineplot(cols[0], cols[1])
2.upto(n_cols - 1) do |i|
UnicodePlot.lineplot!(plot, cols[0], cols[i])
end
plot
end
end
end