Data Visualization
Create terminal-based charts and visualizations from CSV, JSON, or piped data.
Quick Visualizations with YouPlot
YouPlot (uplot) creates Unicode charts in the terminal.
Bar Chart
CODEBLOCK0
Line Chart
CODEBLOCK1
Histogram
CODEBLOCK2
Scatter Plot
CODEBLOCK3
From CSV Files
CODEBLOCK4
From JSON (with jq)
CODEBLOCK5
Termgraph (Python Alternative)
Simple horizontal bar charts:
CODEBLOCK6
With colors:
CODEBLOCK7
Gnuplot (Advanced)
For publication-quality charts:
CODEBLOCK8
Sparklines
Inline mini-charts:
CODEBLOCK9
ASCII Tables
Format data as tables:
CODEBLOCK10
Real-World Examples
Stock Price Chart
CODEBLOCK11
System Metrics
CODEBLOCK12
API Response Times
CODEBLOCK13
Tips
- - Use
-d, for comma-delimited data, -d'\t' for tabs - Use
-H when your data has headers - Pipe through
head or tail to limit data points - Combine with
jq for JSON data extraction - Use
watch for live updating charts: INLINECODE8
技能名称: data-viz
详细描述:
数据可视化
从CSV、JSON或管道数据创建基于终端的图表和可视化。
使用YouPlot快速可视化
YouPlot(uplot)可在终端中创建Unicode图表。
条形图
bash
echo -e Apple,30\nBanana,45\nCherry,20\nDate,35 | uplot bar -d, -t 水果销量
折线图
bash
seq 1 20 | awk {print $1, sin($1/3)*10+10} | uplot line -t 正弦波
直方图
bash
awk BEGIN{for(i=0;i<1000;i++)print rand()} | uplot hist -t 随机分布 -n 20
散点图
bash
awk BEGIN{for(i=0;i<100;i++)print rand()100, rand()100} | uplot scatter -t 随机点
从CSV文件
bash
从CSV生成条形图
cat sales.csv | uplot bar -d, -H -t 月度销量
带表头的折线图
cat timeseries.csv | uplot line -d, -H -t 股票价格
从JSON(配合jq)
bash
从JSON提取数据并绘图
curl -s https://api.example.com/data | jq -r .items[] | \(.name),\(.value) | uplot bar -d,
Termgraph(Python替代方案)
简单的水平条形图:
bash
echo -e 2020 50\n2021 75\n2022 90\n2023 120 | termgraph
带颜色:
bash
echo -e 销售额 150\n成本 80\n利润 70 | termgraph --color green
Gnuplot(高级)
用于出版级图表:
bash
快速折线图
gnuplot -e set terminal dumb; plot sin(x)
从数据文件
gnuplot -e set terminal dumb; plot data.txt with lines
迷你图
内联微型图表:
bash
使用spark(如果已安装)
echo 1 5 22 13 5 | spark
输出:▁▂█▅▂
纯bash迷你图
data=1 5 22 13 5; min=$(echo $data | tr \n | sort -n | head -1); max=$(echo $data | tr \n | sort -n | tail -1); for n in $data; do printf \u258$((7-7*($n-$min)/($max-$min))); done; echo
ASCII表格
将数据格式化为表格:
bash
使用column
echo -e 姓名,分数,等级\nAlice,95,A\nBob,82,B\nCarol,78,C | column -t -s,
使用csvlook(csvkit)
cat data.csv | csvlook
实际应用示例
股票价格图表
bash
获取并绘制股票数据(使用Alpha Vantage免费API)
curl -s https://www.alphavantage.co/query?function=TIME
SERIESDAILY&symbol=AAPL&apikey=demo | \
jq -r .[Time Series (Daily)] | to_entries | .[:20] | reverse | .[] | \(.key) \(.value[4. close]) | \
uplot line -t AAPL股票价格
系统指标
bash
CPU使用率随时间变化
for i in {1..20}; do
top -bn1 | grep Cpu(s) | awk {print 100-$8}
sleep 1
done | uplot line -t CPU使用率%
API响应时间
bash
测量并绘制响应时间
for i in {1..10}; do
curl -s -o /dev/null -w %{time_total}\n https://example.com
done | uplot line -t 响应时间(秒)
提示
- - 使用-d,表示逗号分隔数据,-d\t表示制表符分隔
- 数据包含表头时使用-H
- 通过管道连接head或tail限制数据点数量
- 配合jq进行JSON数据提取
- 使用watch实现实时更新图表:watch -n1 command | uplot bar