从csv中读取并在x

时间:2018-12-31 14:07:00

标签: csv gnuplot file-read

我是gnuplot的新手,被困于绘制两条趋势线。该文件正在跟踪如何评估两个配置文件:低风险和高风险。现在,我想绘制一条趋势线,如下面的R基本图所示,但使用gnuplot。我的数据文件如下:

date,investpercent,expenses,savings,low,high,objective
2015-09-25,5.0,1.0,2.0,1,2,2.0
2016-09-25,6.0,1.0,2.0,1,2,2.0
2017-09-26,6.0,1.0,2.0,2,4,2.0
2018-09-27,5.0,40.0,60.0,10,40,-49904.0
2018-09-27,5.0,40.0,60.0,20,50,-169960.0

This is how I want it to look like

set key autotitle columnhead
plot '~/Downloads/finances.csv' using 1:5

我使用自动标题是因为第一行中的标题,它消除了一个错误,但显然设置了标题,我不需要。知道如何也忽略标头也很高兴。

我的问题是:

  • 如何使用gnuplot使用日期作为x轴的y中第5列和第6列的值绘制趋势?

1 个答案:

答案 0 :(得分:1)

您可以尝试以下方法:

set key autotitle columnhead
set key top left
set datafile separator ","
set timefmt '%Y-%m-%d'
set xdata time
plot 'test.txt' using 1:5 w l t 'low',  'test.txt' using 1:6 w l t 'high'

产生: enter image description here