9 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
3 changed files with 88 additions and 50 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

@@ -10,22 +10,26 @@ 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.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
@@ -87,22 +91,22 @@ module Uplot
# Usage and help messages
main_parser.banner = \
<<~MSG
Program: uplot (Tools for plotting on the terminal)
Version: #{Uplot::VERSION} (using UnicodePlot #{UnicodePlot::VERSION})
Author: kojix2 <2xijok@gmail.com>
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
@@ -110,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
@@ -121,80 +126,80 @@ module Uplot
exit 1
when :barplot, :bar
parser.on('--symbol VAL', String, 'character to be used to plot the bars') 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, 'axis scaling') do |v|
parser.on_head('--xscale VAL', String, 'axis scaling') do |v|
params.xscale = v
end
when :count, :c
parser.on('--symbol VAL', String, 'character to be used to plot the bars') 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, 'approximate number of bins') 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, 'character to be used to plot the bars') 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, 'type of canvas') do |v|
parser.on_head('--canvas VAL', String, 'type of canvas') do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array, 'plotting range for the x coordinate') 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, 'plotting range for the y coordinate') 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, 'plotting range for the x coordinate') 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, 'plotting range for the y coordinate') 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, 'plotting range for the x coordinate') 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, 'plotting range for the y coordinate') 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, 'plotting range for the x coordinate') 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, 'plotting range for the y coordinate') 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, 'plotting range for the x coordinate') 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

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