#plot #list #line #graph #nushell #plugin #numeric

bin+lib nu_plugin_plot

使用数值列表在 nushell 中绘制图表

1 个不稳定版本

0.74.0 2023 年 1 月 11 日

#238 in 可视化

MIT 和可能 CC-PDDC

52KB
1K SLoC

nu_plugin_plot

一个小型 nu 插件,用于将列表作为线图绘制。

安装

由于尚未在 crates.io 上发布,因此您需要克隆此仓库。我假设您已安装 Rust,并且处于 nushell 实例内部。

git clone https://github.com/Euphrasiologist/nu_plugin_plot
cd nu_plugin_plot

cargo build --release
register ./target/release/nu_plugin_plot

# test commands
plot -h
hist -h
xyplot -h

帮助

plothistxyplot 的帮助信息非常相似,所以这里只展示 plot 的帮助信息。

Render an ASCII plot from a list of values.

Usage:
  > plot {flags} 

Flags:
  -h, --help - Display the help message for this command
  --width <Number> - The maximum width of the plot.
  --height <Number> - The maximum height of the plot.
  -t, --title <String> - Provide a title to the plot.
  -l, --legend - Plot a tiny, maybe useful legend.
  -b, --bars - Change lines to bars.
  -s, --steps - Change lines to steps.
  -p, --points - Change lines to points.

示例

## basic 'plot'

# plot a single line
let one = (seq 0.0 0.01 20.0 | math sin)
$one | plot

# plot two lines
let two = (seq 1.0 0.01 21.0 | math sin)
[$one $two] | plot

# plot four lines with a legend and title
let three = (seq 2.0 0.01 22.0 | math sin)
let four = (seq 3.0 0.01 23.0 | math sin)

[$one $two $three $four] | plot -l -t "Four sine lines!"

# bivariate 'xyplot'
# input must be a two element nested list

# make a nice ellipse
[$one $two] | xyplot

# bivariate line plot
# diagonal dots!
[(seq 1 100) (seq 1 100 | reverse)] | xyplot -p

# plot histograms

# compare two uniform distributions
let r1 = (seq 1 100 | each { random integer ..30})
let r2 = (seq 1 100 | each { random integer ..30})

# -b for bars, otherwise you get lines by default
[$r1 $r2] | hist -b
# up the number of bins
[$r1 $r2] | hist -b --bins 50

# If you've got R installed (& Rscript)
# go crazy!
# forget ggplot!
let x = (Rscript -e "cat(dnorm(seq(-4, 4, length=100)))" | into string | split row ' ' | into decimal)
let y = (Rscript -e "cat(dnorm(seq(-3, 6, length=100)))" | into string | split row ' ' | into decimal)

[$x $y] | plot -bl -t "Two normal distributions"

功能

绘图

  • 单个数值列表
  • 数值列表列表
    • 支持颜色
    • 带有图例
    • 带有标题
  • 散点图(作为两个数值列表的列表)
  • 直方图(列表以条形图形式渲染)
  • 嵌套 xyplot(即在同一图上绘制多个 xyplot...)
  • 记录...?

请帮助我改进这个项目!提交问题/PR,我很乐意聊天。

nushell 内的颜色渲染稍微有些令人困惑 - 您可能会注意到我在源代码中包含了自定义修改版的 textplotsdrawille。这是因为它们在插件内的颜色渲染方法不起作用 - 我仍然不知道为什么。

依赖项

约 12-25MB
约 355K SLoC