【问题标题】:Gnuplot, how plot the month in a title or legend?Gnuplot,如何在标题或图例中绘制月份?
【发布时间】:2013-12-24 23:40:01
【问题描述】:

有一个新问题。有人可以帮我解决这个问题吗?

我的数据文件的一部分是

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

非常感谢!!我花了一天多的时间寻找解决方案,现在。 . .是的。

【问题讨论】:

    标签: date gnuplot title legend


    【解决方案1】:

    原则上,要从数据文件中提取某个值,可以使用Gnuplot: How to load and display single numeric value from data file 中所示的stats 命令(至少需要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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多