bash - 使用 gnuplot 从 CSV 生成图表

标签 bash unix gnuplot

我收到一个错误:

跳过没有有效点的数据文件

当尝试使用 gnuplot 从 csv 文件生成图形时,非常感谢任何帮助!

样本.csv

timestamp,unit,maximum,average
Thu Jan 29 10:57:00 GMT 2015,Percent,22.96,7.723999999999999
Thu Jan 29 10:52:00 GMT 2015,Percent,62.79,26.227999999999998
Thu Jan 29 10:47:00 GMT 2015,Percent,46.54,15.075999999999999

run_gnuplot.sh

#!/bin/bash
gnuplot << eor
set terminal png 
set output 'output.png'
set style data linespoints
set datafile separator ","
set xlabel "timestamp"
set ylabel "percent"
plot "sample.csv" using 1:3 title "Maximum" using 1:4 title "Average"  
eor

错误:

bash-4.1$ ./run_gnuplot.sh 
Could not find/open font when opening font "arial", using internal non-scalable font

gnuplot> plot "sample.csv" using 1:3 title "Maximum" using 1:4 title "Average"  
                                           ^
         line 0: warning: Skipping data file with no valid points

gnuplot> plot "sample.csv" using 1:3 title "Maximum" using 1:4 title "Average"  
                                                     ^
         line 0: x range is invalid

最佳答案

您必须告诉 gnuplot,第一列将被视为时间数据

set xdata time

您还必须给出解析第一列的时间格式。不幸的是,gnuplot 不支持在星期几中阅读。

要么更改写入文件的数据格式,要么使用 cut 等外部工具过滤星期几:

set xdata time
set timefmt '%b %d %H:%M:%S GMT %Y'
set datafile separator ','

plot '< tail -n +2 sample.csv | cut -f 1 --complement -d" "' using 1:3, '' using 1:4

跳过第一行的 tail 部分在 5.0 版本中不是必需的。

关于bash - 使用 gnuplot 从 CSV 生成图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28281139/

相关文章:

c - C 套接字 sockaddr 和 sockaddr_storage 背后的推理

c++ - gnuplot-iostream 无法编译

Bash - 比较具有不同分隔符的字符串的简单方法?

在冒险游戏中随机连接房间

python - Bash 脚本到 Conda 安装 requirements.txt 与 PIP 跟进

linux - 如何根据上一个命令比较得到下一个输入命令[bash-script]

gnuplot - Maxima 中的极坐标等高线图

conditional - Gnuplot:带线条的条件绘图($2 == 15 ? $2 : '1/0')

bash - 使用 bash 解析 .env 文件并将其注入(inject)命令行

bash - 为什么 cut 命令对 "docker image ls"命令不起作用?