[英]How to use GnuPlot to plot a time series chart from a CSV file date and time stored in separate columns?
Lets' take this as the data file: 让我们将其作为数据文件:
2012-06-01, 01:00, 1
2012-06-01, 02:00, 2
2012-06-01, 03:00, 4
2012-06-01, 04:00, 3
...
2012-06-02, 01:00, 5
2012-06-02, 02:00, 2
2012-06-02, 03:00, 1
2012-06-02, 04:00, 1
...
I know how to set timefmt
and xdata
to plot time series when date and time are represented with a single field, but how to plot this with GnuPlot when time and date are stored in separate columns? 我知道当日期和时间用单个字段表示时,如何设置timefmt
和xdata
以绘制时间序列,但是当时间和日期存储在单独的列中时,如何使用GnuPlot绘制时间序列?
Not too differently than you would if they were spaces... 如果它们是空格,则与您没什么不同...
set timefmt '%Y-%m-%d, %H:%M'
set xdata time
set datafile sep ','
plot 'test.dat' u 1:3 w lines
I don't know if you've used timefmt with spaces in it before either (for regular space separated datafiles) but in that case, you specify the column where the time-data starts -- gnuplot automatically looks however many columns it needs to fill out the full time format. 我不知道您是否曾经在其中使用过timefmt(对于常规的用空格分隔的数据文件),但是在那种情况下,您指定时间数据开始的列-gnuplot自动查找需要多少列填写完整时间格式。 Of course, you need a full using specification (in this case that means designating that the data is in the 3rd column -- note, not the second as you might expect). 当然,您需要一个完整的使用规范(在这种情况下,这意味着将数据指定在第三列中-注意,而不是您期望的第二列)。
(tested on gnuplot 4.4 -- OS X) (在gnuplot 4.4上测试-OS X)
Running Arch Linux Gnuplot 4.6 patchlevel 3 运行Arch Linux Gnuplot 4.6补丁程序级别3
I couldn't get mgilson's code snippet to work. 我无法获取mgilson的代码段。 I needed to set the xrange
before it would stop complaining 我需要设置xrange
才能停止抱怨
all points y value undefined!
I had to 我不得不
set xrange["2012-06-01, 01:00":"2012-06-02, 05:00"]
and finally got a pretty plot 终于有了一个漂亮的情节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.