使用 gnuplot 从 CSV 生成图表

Generate a graph from CSV using gnuplot

我遇到一个错误:

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

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

sample.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

5.0 版不需要跳过第一行的 tail 部分。