mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-19 19:08:07 +08:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
00c2ce9b44 | ||
![]() |
84196c197d | ||
![]() |
c40c59a21d | ||
![]() |
c4f21df588 | ||
![]() |
39166894a3 | ||
![]() |
7b8213833f | ||
![]() |
9090bbf51b | ||
![]() |
428d525c5f | ||
![]() |
6ebc707c51 | ||
![]() |
c73da80de6 | ||
![]() |
2e8641ccea | ||
![]() |
1b43f7d48f | ||
![]() |
d8396fecf9 | ||
![]() |
4660c2ab02 | ||
![]() |
d7e49f048f |
47
README.md
47
README.md
@@ -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).
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Uplot
|
||||
VERSION = '0.2.5'
|
||||
VERSION = '0.2.7'
|
||||
end
|
||||
|
Reference in New Issue
Block a user