遇到新问题了。有人可以帮我解决这个问题吗?
我的数据文件的一部分是
06-07-2013,13461,0,7464,0,
07-07-2013,14494,0,5584,0,
08-07-2013,149,13394,3412,2471,
09-07-2013,295,14058,3005,3201,
10-07-2013,194,8308,3264,4026,
11-07-2013,14,4597,3162,1945,
12-07-2013,113,4447,3009,2268,
并且想要知道的名字 图例或情节标题中的月份和年份(在本例中为 2013 年 7 月)。如何首先从数据文件中获取月份(值),然后将其写入文本?
哇,真是美得近乎完美,看剧情里的圆圈。 今年有点晚了(笑)。
http://ccvd.eu/downloads/Jul.png
我捕获了他,骗子是 fmt = '%d-%m-%Y' 代替 fmt = '%d-%m-%<强>y'
http://ccvd.eu/downloads/Jul.png
非常感谢!!我花了一天多的时间寻找解决方案,现在。 。 。是的。
最佳答案
原则上,要从数据文件中提取特定值,您可以使用 stats
命令,如Gnuplot: How to load and display single numeric value from data file所示(至少需要版本 4.6.0)。
但是stats
不能使用set xdata time
直接处理时间数据,你需要一个小技巧。在 using
语句中,您必须以字符串形式访问第一列,并使用 strptime
将其格式化为时间戳。
之后,您可以使用 strftime
格式化此时间戳并将其放入标题或图例中:
stats 'file.txt' using (strptime('%d-%m-%Y', stringcolumn(1))) every ::0::0
set title strftime('%B %Y', STATS_max)
只有在调用stats
之后,您才可以使用set xdata time
切换到时间数据。
所以更完整的脚本可能看起来像
set datafile separator ','
fmt = '%d-%m-%Y'
file = 'file.txt'
stats file using (strptime(fmt, stringcolumn(1))) every ::0::0 nooutput
date = strftime('%B %Y', STATS_max)
set title 'Data of '.date
set timefmt fmt
set xdata time
plot file using 1:2 title 'again '.date
关于date - Gnuplot,如何在标题或图例中绘制月份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20767824/