mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 23:51:12 +08:00
Add lineplot
This commit is contained in:
parent
e69d1caed7
commit
4a49711d57
@ -29,6 +29,10 @@ module Uplot
|
|||||||
case @ptype
|
case @ptype
|
||||||
when 'hist', 'histogram'
|
when 'hist', 'histogram'
|
||||||
histogram(input_lines).render
|
histogram(input_lines).render
|
||||||
|
when 'line', 'lineplot'
|
||||||
|
line(input_lines).render
|
||||||
|
when 'lines'
|
||||||
|
lines(input_lines).render
|
||||||
end
|
end
|
||||||
|
|
||||||
puts input_lines if @params[:p]
|
puts input_lines if @params[:p]
|
||||||
@ -38,5 +42,32 @@ module Uplot
|
|||||||
series = input_lines.map(&:to_f)
|
series = input_lines.map(&:to_f)
|
||||||
UnicodePlot.histogram(series, nbins: @params[:nbins])
|
UnicodePlot.histogram(series, nbins: @params[:nbins])
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user