11 Commits

Author SHA1 Message Date
kojix2
34ae2b5815 v0.2.5 2020-10-11 00:14:18 +09:00
kojix2
7e8dc6190c Fix arg order 2020-10-11 00:11:54 +09:00
kojix2
ba105ab1f3 Improved help desc 2020-10-10 23:58:53 +09:00
kojix2
96a1d1feb9 Fix style 2020-10-10 23:58:53 +09:00
kojix2
2b65dae60c Add a image to README.md 2020-10-10 23:35:26 +09:00
kojix2
943d4e6c44 Use keyword arg for count 2020-10-10 23:21:55 +09:00
kojix2
de33805c56 Drop support for ruby 2.3 2020-10-10 23:18:27 +09:00
kojix2
de3a366d15 Fix debug option 2020-10-10 23:16:15 +09:00
kojix2
4544c0e456 Removed count option for barplot 2020-10-10 23:08:20 +09:00
kojix2
ccfbaa7bde Allows you to specify the output file 2020-09-29 18:16:42 +09:00
kojix2
3aceae9279 Improved command description 2020-09-29 18:14:41 +09:00
6 changed files with 63 additions and 69 deletions

View File

@@ -26,27 +26,7 @@ ruby -r numo/narray -e "puts Numo::DFloat.new(1000).rand_norm.to_a" \
| uplot hist --nbins 15
```
```
┌ ┐
[-4.5, -4.0) ┤ 1
[-4.0, -3.5) ┤ 0
[-3.5, -3.0) ┤ 1
[-3.0, -2.5) ┤▇▇ 9
[-2.5, -2.0) ┤▇▇▇ 15
[-2.0, -1.5) ┤▇▇▇▇▇▇▇▇▇ 50
[-1.5, -1.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 97
[-1.0, -0.5) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 154
[-0.5, 0.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 193
[ 0.0, 0.5) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 165
[ 0.5, 1.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 152
[ 1.0, 1.5) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 86
[ 1.5, 2.0) ┤▇▇▇▇▇▇▇▇▇ 51
[ 2.0, 2.5) ┤▇▇▇▇ 21
[ 2.5, 3.0) ┤▇ 3
[ 3.0, 3.5) ┤ 2
└ ┘
Frequency
```
<img src="https://i.imgur.com/wpsoGJq.png" width="75%" height="75%"></img>
**scatter**

View File

@@ -25,10 +25,10 @@ module Uplot
delimiter = parser.delimiter
transpose = parser.transpose
headers = parser.headers
pass = parser.pass
output = parser.output
count = parser.count
fmt = parser.fmt
debug = parser.debug
@debug = parser.debug
if command == :colors
Plot.colors
@@ -36,33 +36,47 @@ module Uplot
end
# Sometimes the input file does not end with a newline code.
while input = Kernel.gets(nil)
while (input = Kernel.gets(nil))
input.freeze
@raw_inputs << input
@data = Preprocessing.input(input, delimiter, headers, transpose)
pp @data if @debug
case command
when :bar, :barplot
Plot.barplot(data, params, @count)
when :count, :c
Plot.barplot(data, params, count = true)
when :hist, :histogram
Plot.histogram(data, params)
when :line, :lineplot
Plot.line(data, params)
when :lines, :lineplots
Plot.lines(data, params, fmt)
when :scatter, :s
Plot.scatter(data, params, fmt)
when :density, :d
Plot.density(data, params, fmt)
when :box, :boxplot
Plot.boxplot(data, params)
else
raise "unrecognized plot_type: #{command}"
end.render($stderr)
plot = case command
when :bar, :barplot
Plot.barplot(data, params)
when :count, :c
Plot.barplot(data, params, count: true)
when :hist, :histogram
Plot.histogram(data, params)
when :line, :lineplot
Plot.line(data, params)
when :lines, :lineplots
Plot.lines(data, params, fmt)
when :scatter, :s
Plot.scatter(data, params, fmt)
when :density, :d
Plot.density(data, params, fmt)
when :box, :boxplot
Plot.boxplot(data, params)
else
raise "unrecognized plot_type: #{command}"
end
print input if output
if output.is_a?(IO)
plot.render(output)
else
File.open(output, 'w') do |f|
plot.render(f)
end
end
if pass.is_a?(IO)
print input
elsif pass
File.open(pass, 'w') do |f|
f.print(input)
end
end
end
end
end

View File

@@ -7,7 +7,7 @@ module Uplot
class Command
class Parser
attr_reader :command, :params,
:delimiter, :transpose, :headers, :output, :count, :fmt, :debug
:delimiter, :transpose, :headers, :pass, :output, :fmt, :debug
def initialize
@command = nil
@@ -16,8 +16,8 @@ module Uplot
@delimiter = "\t"
@transpose = false
@headers = nil
@output = false
@count = false
@pass = false
@output = $stderr
@fmt = 'xyy'
@debug = false
end
@@ -26,49 +26,52 @@ module Uplot
OptionParser.new do |opt|
opt.program_name = 'uplot'
opt.version = Uplot::VERSION
opt.on('-O', '--output', TrueClass) do |v|
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]') do |v|
@pass = v || $stdout
end
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
@output = v
end
opt.on('-d', '--delimiter VAL', 'use DELIM instead of TAB for field delimiter', String) do |v|
opt.on('-d', '--delimiter VAL', String, 'use DELIM instead of TAB for field delimiter') do |v|
@delimiter = v
end
opt.on('-H', '--headers', 'specify that the input has header row', TrueClass) do |v|
opt.on('-H', '--headers', TrueClass, 'specify that the input has header row') do |v|
@headers = v
end
opt.on('-T', '--transpose', TrueClass) do |v|
@transpose = v
end
opt.on('-t', '--title VAL', 'print string on the top of plot', String) do |v|
opt.on('-t', '--title VAL', String, 'print string on the top of plot') do |v|
params.title = v
end
opt.on('-x', '--xlabel VAL', 'print string on the bottom of the plot', String) do |v|
opt.on('-x', '--xlabel VAL', String, 'print string on the bottom of the plot') do |v|
params.xlabel = v
end
opt.on('-y', '--ylabel VAL', 'print string on the far left of the plot', String) do |v|
opt.on('-y', '--ylabel VAL', String, 'print string on the far left of the plot') do |v|
params.ylabel = v
end
opt.on('-w', '--width VAL', 'number of characters per row', Integer) do |v|
opt.on('-w', '--width VAL', Integer, 'number of characters per row') do |v|
params.width = v
end
opt.on('-h', '--height VAL', 'number of rows', Numeric) do |v|
opt.on('-h', '--height VAL', Numeric, 'number of rows') do |v|
params.height = v
end
opt.on('-b', '--border VAL', 'specify the style of the bounding box', String) do |v|
opt.on('-b', '--border VAL', String, 'specify the style of the bounding box') do |v|
params.border = v.to_sym
end
opt.on('-m', '--margin VAL', 'number of spaces to the left of the plot', Numeric) do |v|
opt.on('-m', '--margin VAL', Numeric, 'number of spaces to the left of the plot') do |v|
params.margin = v
end
opt.on('-p', '--padding VAL', 'space of the left and right of the plot', Numeric) do |v|
opt.on('-p', '--padding VAL', Numeric, 'space of the left and right of the plot') do |v|
params.padding = v
end
opt.on('-c', '--color VAL', 'color of the drawing', String) do |v|
opt.on('-c', '--color VAL', String, 'color of the drawing') do |v|
params.color = v =~ /\A[0-9]+\z/ ? v.to_i : v.to_sym
end
opt.on('--[no-]labels', 'hide the labels', TrueClass) do |v|
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
params.labels = v
end
opt.on('--fmt VAL', 'xyy, xyxy', String) do |v|
opt.on('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', 'xyy : header is like x, y1, y2, y2, y3...') do |v|
@fmt = v
end
opt.on('--debug', TrueClass) do |v|
@@ -121,9 +124,6 @@ module Uplot
parser.on('--xscale VAL', String) do |v|
params.xscale = v
end
parser.on('--count', TrueClass) do |v|
@count = v
end
when :count, :c
parser.on('--symbol VAL', String) do |v|
@@ -221,4 +221,4 @@ module Uplot
end
end
end
end
end

View File

@@ -7,7 +7,7 @@ module Uplot
module Plot
module_function
def barplot(data, params, count = false)
def barplot(data, params, count: false)
headers = data.headers
series = data.series
if count

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Uplot
VERSION = '0.2.4'
VERSION = '0.2.5'
end

View File

@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
MSG
spec.homepage = 'https://github.com/kojix2/uplot'
spec.license = 'MIT'
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
spec.files = Dir['*.{md,txt}', '{lib,exe}/**/*']
spec.bindir = 'exe'