mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 06:46:11 +08:00
Add hist
This commit is contained in:
parent
eeb5038602
commit
6cf861aadf
30
exe/uplot
30
exe/uplot
@ -1,3 +1,33 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'uplot'
|
||||
require 'unicode_plot'
|
||||
require 'optparse'
|
||||
|
||||
parser = OptionParser.new
|
||||
|
||||
subparsers = Hash.new do |_h, k|
|
||||
warn "no such subcommand: #{k}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
params = {}
|
||||
|
||||
subparsers['hist'] = OptionParser.new.tap do |opt|
|
||||
opt.on('--nbins VAL') { |v| params[:nbins] = v.to_i }
|
||||
opt.on('-p') { |v| params[:p] = v }
|
||||
end
|
||||
|
||||
parser.order!(ARGV)
|
||||
params[:type] = ARGV.shift
|
||||
subparsers[params[:type]].parse!(ARGV) unless ARGV.empty?
|
||||
|
||||
input_lines = readlines.map(&:chomp)
|
||||
|
||||
case params[:type]
|
||||
when 'hist', 'histogram'
|
||||
series = input_lines.map(&:to_f)
|
||||
UnicodePlot.histogram(series, nbins: params[:nbins]).render
|
||||
end
|
||||
|
||||
puts input_lines if params[:p]
|
||||
|
@ -1,6 +1 @@
|
||||
require 'uplot/version'
|
||||
|
||||
module Uplot
|
||||
class Error < StandardError; end
|
||||
# Your code goes here...
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user