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) :bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb)
:construction: Under development! :construction:
## Installation ## Installation
``` ```
@@ -26,22 +24,57 @@ ruby -r numo/narray -e "puts Numo::DFloat.new(1000).rand_norm.to_a" \
| uplot hist --nbins 15 | 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** **scatter**
```sh ```sh
wget https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv -qO - \ curl -s https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv \
| cut -f1-4 -d, \ | cut -f1-4 -d, \
| uplot scatter -H -d, -t IRIS -m 10 | 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 ## Development
Let's keep it simple.
## Contributing ## Contributing
Bug reports and pull requests are welcome on GitHub at [https://github.com/kojix2/uplot](https://github.com/kojix2/uplot). Bug reports and pull requests are welcome on GitHub at [https://github.com/kojix2/uplot](https://github.com/kojix2/uplot).
## License ## 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 module Uplot
class Command 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( Params = Struct.new(
# Sort me! # Sort me!
:title, :title,

View File

@@ -26,7 +26,12 @@ module Uplot
OptionParser.new do |opt| OptionParser.new do |opt|
opt.program_name = 'uplot' opt.program_name = 'uplot'
opt.version = Uplot::VERSION opt.version = Uplot::VERSION
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]') do |v| 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 @pass = v || $stdout
end end
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v| opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
@@ -86,20 +91,22 @@ module Uplot
# Usage and help messages # Usage and help messages
main_parser.banner = \ main_parser.banner = \
<<~MSG <<~MSG
Program: uplot (Tools for plotting on the terminal) 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] Usage: uplot <command> [options]
Command: barplot bar Commands:
barplot bar
histogram hist histogram hist
lineplot line lineplot line
lineplots lines
scatter s scatter s
density d density d
boxplot box boxplot box
colors colors
Options:
MSG MSG
end end
end end
@@ -107,9 +114,10 @@ module Uplot
def sub_parser def sub_parser
@sub_parser ||= create_default_parser do |parser| @sub_parser ||= create_default_parser do |parser|
parser.banner = <<~MSG parser.banner = <<~MSG
Usage: uplot #{command} [options] Usage: uplot #{command} [options]
Options: Options for #{command}:
MSG MSG
case command case command
@@ -118,80 +126,80 @@ module Uplot
exit 1 exit 1
when :barplot, :bar 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 params.symbol = v
end end
parser.on('--xscale VAL', String) do |v| parser.on_head('--xscale VAL', String, 'axis scaling') do |v|
params.xscale = v params.xscale = v
end end
when :count, :c 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 params.symbol = v
end end
when :histogram, :hist 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 params.nbins = v
end end
parser.on('--closed VAL', String) do |v| parser.on_head('--closed VAL', String) do |v|
params.closed = v params.closed = v
end 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 params.symbol = v
end end
when :lineplot, :line when :lineplot, :line
parser.on('--canvas VAL', String) do |v| parser.on_head('--canvas VAL', String, 'type of canvas') do |v|
params.canvas = v params.canvas = v
end 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) params.xlim = v.take(2)
end 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) params.ylim = v.take(2)
end end
when :lineplots, :lines when :lineplots, :lines
parser.on('--canvas VAL', String) do |v| parser.on_head('--canvas VAL', String) do |v|
params.canvas = v params.canvas = v
end 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) params.xlim = v.take(2)
end 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) params.ylim = v.take(2)
end end
when :scatter, :s when :scatter, :s
parser.on('--canvas VAL', String) do |v| parser.on_head('--canvas VAL', String) do |v|
params.canvas = v params.canvas = v
end 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) params.xlim = v.take(2)
end 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) params.ylim = v.take(2)
end end
when :density, :d when :density, :d
parser.on('--grid', TrueClass) do |v| parser.on_head('--grid', TrueClass) do |v|
params.grid = v params.grid = v
end 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) params.xlim = v.take(2)
end 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) params.ylim = v.take(2)
end end
when :boxplot, :box 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) params.xlim = v.take(2)
end end
when :colors when :colors
parser.on('-n', '--names', TrueClass) do |v| parser.on_head('-n', '--names', TrueClass) do |v|
@color_names = v @color_names = v
end end

View File

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

View File

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