15 Commits

Author SHA1 Message Date
kojix2
00c2ce9b44 v0.2.7 2020-10-12 23:08:32 +09:00
kojix2
84196c197d Revert "Show message when No input data provided"
Uplot should expect cases where data takes a long time to reach the standard input.
This mechanism is not appropriate.

This reverts commit c40c59a21d.
2020-10-12 20:44:31 +09:00
kojix2
c40c59a21d Show message when No input data provided
Thank you csvkit developers
2020-10-12 17:10:25 +09:00
kojix2
c4f21df588 Show subcommand options ahead 2020-10-12 16:45:28 +09:00
kojix2
39166894a3 Improved help banner
Summary width 24
2020-10-12 16:14:51 +09:00
kojix2
7b8213833f Removed 'under development' in README 2020-10-12 14:57:03 +09:00
kojix2
9090bbf51b Fix help banner 2020-10-12 14:52:56 +09:00
kojix2
428d525c5f Add sample codes to README 2020-10-12 14:24:02 +09:00
kojix2
6ebc707c51 Add images to README.md 2020-10-12 14:04:36 +09:00
kojix2
c73da80de6 v0.2.6 2020-10-12 07:45:42 +09:00
kojix2
2e8641ccea Improved descs 2020-10-11 09:23:57 +09:00
kojix2
1b43f7d48f Add comment about pass 2020-10-11 08:29:02 +09:00
kojix2
d8396fecf9 Rubocop auto correct 2020-10-11 08:28:39 +09:00
kojix2
4660c2ab02 Extract case-branching by fmt into another method 2020-10-11 08:02:43 +09:00
kojix2
d7e49f048f Add a comment to params 2020-10-11 07:55:20 +09:00
5 changed files with 111 additions and 69 deletions

View File

@@ -9,8 +9,6 @@ Create ASCII charts on the terminal with data from standard streams in the pipel
:bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb)
:construction: Under development! :construction:
## Installation
```
@@ -26,22 +24,57 @@ ruby -r numo/narray -e "puts Numo::DFloat.new(1000).rand_norm.to_a" \
| uplot hist --nbins 15
```
<img src="https://i.imgur.com/wpsoGJq.png" width="75%" height="75%"></img>
<img src="https://i.imgur.com/wpsoGJq.png" width="75%" height="75%">
```sh
echo "from numpy import random;" \
"n = random.randn(10000);" \
"print('\n'.join(str(i) for i in n))" \
| python \
| uplot hist --nbins 20
```
<img src="https://i.imgur.com/97R2MQx.png" width="75%" height="75%">
**scatter**
```sh
wget https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv -qO - \
| cut -f1-4 -d, \
| uplot scatter -H -d, -t IRIS -m 10
curl -s https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv \
| cut -f1-4 -d, \
| uplot scatter -H -d, -t IRIS
```
<img src="https://i.imgur.com/STX7bFT.png" width="75%" height="75%">
**line**
```sh
curl -s https://www.mhlw.go.jp/content/pcr_positive_daily.csv \
| cut -f2 -d, \
| uplot line -w 50 -h 15 -t 'PCR positive tests' --xlabel Date --ylabel number
```
<img src="https://i.imgur.com/PVl5dsa.png" width="75%" height="75%">
**box**
```sh
curl -s https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv \
| cut -f1-4 -d, \
| uplot box -H -d, -t IRIS
```
<img src="https://i.imgur.com/sNI4SmN.png" width="75%" height="75%">
## Development
Let's keep it simple.
## Contributing
Bug reports and pull requests are welcome on GitHub at [https://github.com/kojix2/uplot](https://github.com/kojix2/uplot).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
[MIT License](https://opensource.org/licenses/MIT).

View File

@@ -2,6 +2,11 @@
module Uplot
class Command
# UnicodePlot parameters.
# * Normally in a Ruby program, you might use hash for the parameter object.
# * Here, I use Struct for 2 safety reason.
# * The keys are static in Struct.
# * Struct does not conflict with keyword arguments. Hash dose.
Params = Struct.new(
# Sort me!
:title,

View File

@@ -10,23 +10,28 @@ module Uplot
:delimiter, :transpose, :headers, :pass, :output, :fmt, :debug
def initialize
@command = nil
@params = Params.new
@command = nil
@params = Params.new
@delimiter = "\t"
@transpose = false
@headers = nil
@pass = false
@output = $stderr
@fmt = 'xyy'
@debug = false
@delimiter = "\t"
@transpose = false
@headers = nil
@pass = false
@output = $stderr
@fmt = 'xyy'
@debug = false
end
def create_default_parser
OptionParser.new do |opt|
opt.program_name = 'uplot'
opt.version = Uplot::VERSION
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]') do |v|
opt.program_name = 'uplot'
opt.version = Uplot::VERSION
opt.summary_width = 24
opt.on_tail('') # Add a blank line at the end
opt.separator('')
opt.on('Options:')
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]',
'for inserting uplot in the middle of Unix pipes') do |v|
@pass = v || $stdout
end
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
@@ -86,20 +91,22 @@ module Uplot
# Usage and help messages
main_parser.banner = \
<<~MSG
Program: uplot (Tools for plotting on the terminal)
Version: #{Uplot::VERSION} (using unicode_plot #{UnicodePlot::VERSION})
Version: #{Uplot::VERSION} (using UnicodePlot #{UnicodePlot::VERSION})
Source: https://github.com/kojix2/uplot
Usage: uplot <command> [options]
Command: barplot bar
histogram hist
lineplot line
scatter s
density d
boxplot box
colors
Options:
Commands:
barplot bar
histogram hist
lineplot line
lineplots lines
scatter s
density d
boxplot box
colors
MSG
end
end
@@ -107,9 +114,10 @@ module Uplot
def sub_parser
@sub_parser ||= create_default_parser do |parser|
parser.banner = <<~MSG
Usage: uplot #{command} [options]
Options:
Options for #{command}:
MSG
case command
@@ -118,80 +126,80 @@ module Uplot
exit 1
when :barplot, :bar
parser.on('--symbol VAL', String) do |v|
parser.on_head('--symbol VAL', String, 'character to be used to plot the bars') do |v|
params.symbol = v
end
parser.on('--xscale VAL', String) do |v|
parser.on_head('--xscale VAL', String, 'axis scaling') do |v|
params.xscale = v
end
when :count, :c
parser.on('--symbol VAL', String) do |v|
parser.on_head('--symbol VAL', String, 'character to be used to plot the bars') do |v|
params.symbol = v
end
when :histogram, :hist
parser.on('-n', '--nbins VAL', Numeric) do |v|
parser.on_head('-n', '--nbins VAL', Numeric, 'approximate number of bins') do |v|
params.nbins = v
end
parser.on('--closed VAL', String) do |v|
parser.on_head('--closed VAL', String) do |v|
params.closed = v
end
parser.on('--symbol VAL', String) do |v|
parser.on_head('--symbol VAL', String, 'character to be used to plot the bars') do |v|
params.symbol = v
end
when :lineplot, :line
parser.on('--canvas VAL', String) do |v|
parser.on_head('--canvas VAL', String, 'type of canvas') do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
when :lineplots, :lines
parser.on('--canvas VAL', String) do |v|
parser.on_head('--canvas VAL', String) do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
when :scatter, :s
parser.on('--canvas VAL', String) do |v|
parser.on_head('--canvas VAL', String) do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
when :density, :d
parser.on('--grid', TrueClass) do |v|
parser.on_head('--grid', TrueClass) do |v|
params.grid = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
when :boxplot, :box
parser.on('--xlim VAL', Array) do |v|
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
when :colors
parser.on('-n', '--names', TrueClass) do |v|
parser.on_head('-n', '--names', TrueClass) do |v|
@color_names = v
end

View File

@@ -53,7 +53,7 @@ module Uplot
(method1.to_s + '!').to_sym
end
def xyy_plot(data, method1, params)
def plot_xyy(data, method1, params)
headers = data.headers
series = data.series
method2 = get_method2(method1)
@@ -70,7 +70,7 @@ module Uplot
plot
end
def xyxy_plot(data, method1, params)
def plot_xyxy(data, method1, params)
headers = data.headers
series = data.series
method2 = get_method2(method1)
@@ -87,34 +87,30 @@ module Uplot
plot
end
def lines(data, params, fmt = 'xyy')
check_series_size(data, fmt)
def plot_fmt(data, fmt, method1, params)
case fmt
when 'xyy'
xyy_plot(data, :lineplot, params)
plot_xyy(data, method1, params)
when 'xyxy'
xyxy_plot(data, :lineplot, params)
plot_xyxy(data, method1, params)
else
raise "Unknown format: #{fmt}"
end
end
def lines(data, params, fmt = 'xyy')
check_series_size(data, fmt)
plot_fmt(data, fmt, :lineplot, params)
end
def scatter(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt
when 'xyy'
xyy_plot(data, :scatterplot, params)
when 'xyxy'
xyxy_plot(data, :scatterplot, params)
end
plot_fmt(data, fmt, :scatterplot, params)
end
def density(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt
when 'xyy'
xyy_plot(data, :densityplot, params)
when 'xyxy'
xyxy_plot(data, :densityplot, params)
end
plot_fmt(data, fmt, :densityplot, params)
end
def boxplot(data, params)

View File

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