2

have a new problem. Can someone help me with this?

A part of my datafile is

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,    

And want to have the name of the month and the year (in this case july 2013) in the legend or the title of the plot. How can I get first the month(value) out of the datafile and second make a text of it?

Woow, it is a beauty and almost perfect, look to the circle in the plot. The Year is some late (lol).

http://ccvd.eu/downloads/Jul.png

I got him, the tricker was fmt = '%d-%m-%Y' in place of fmt = '%d-%m-%y'

http://ccvd.eu/downloads/Jul.png

Thank you so much!! I was for more then a day looking for the solution and now . . . YES.

Con
  • 197
  • 2
  • 10

1 Answers1

2

In principle, to extract a certain value from a data file, you can use the stats command like shown in Gnuplot: How to load and display single numeric value from data file (requires at least version 4.6.0).

But stats does not work directly with time data using set xdata time, you need a little trick. In the using statement you must access the first column as string and format it to a time stamp with strptime.

After that you can format this time stamp with strftime and put it in the title or the legend:

stats 'file.txt' using (strptime('%d-%m-%Y', stringcolumn(1))) every ::0::0
set title strftime('%B %Y', STATS_max)

Only after calling stats you can switch to time data with set xdata time.

So a more complete script could look like

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
Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187