When plotting timedate data into a table precision gets lost.
Let's call this a bug or at least an unnecessary limitation...
I don't see a reason why timedata plotted into a table should be limited to 4 digits, instead of covering second or even millisecond precision.
Code:
### missing precision with timecolumn() together with table
reset session
# create some random test data
myTimeFmt = "%d.%m.%Y %H:%M:%S"
set print $Data
do for [i=0:20] {
print sprintf("%s %.3f",strftime(myTimeFmt,time(0)+i*1200),rand(0))
}
set print
set table $TimeTable
plot $Data u (timecolumn(1,myTimeFmt)):3 w table
unset table
print $TimeTable
set format x "%H:%M" timedate
plot $Data u (timecolumn(1,myTimeFmt)):3 w lp pt 7 ti "Original data", \
$TimeTable u 1:2 w lp pt 6 lc "red" ti "Data from table"
### end of code
Result:
1.60948e+09 0.72
1.60948e+09 0.539
1.60948e+09 0.206
1.60948e+09 0.797
1.60948e+09 0.231
1.60948e+09 0.844
1.60949e+09 0.2
1.60949e+09 0.008
1.60949e+09 0.209
1.60949e+09 0.857
1.60949e+09 0.518
1.60949e+09 0.471
1.60949e+09 0.01
1.60949e+09 0.909
1.60949e+09 0.62
1.6095e+09 0.029
1.6095e+09 0.039
1.6095e+09 0.422
1.6095e+09 0.927
1.6095e+09 0.786
1.6095e+09 0.243
Diff:
the following is also limited in precision, it is basically identical to what timecolumn() does.
plot $Data u (strptime(myTimeFmt,strcol(1)." ".strcol(2))):3 w tableFrom "help with table"
In your test case that would mean replacing
with
Sorry, my fault for not having checked
help with table. Besides this, I thought standard precision for%gwas 6 digits. So, no bug at all. Happy New Year!Last edit: theozh 2021-01-01
Now, I nevertheless have an issue with this:
How would I use this together with
smooth freq, e.g. for creating histograms with a bin size of a few hours or minutes or even seconds?Variation 1:
Variation 2: (using
sprintf())Variation 3: (using
sprintf()andwith table)Neither Variation 1, nor Variation 2, nor Variation 3 will do the job.
Variation 1 does not work because of missing precision and
Variation 2 does not work because
smooth freqwill not work with string values andVariation 3 does not work because
smooth freqdoes not work together withwith table.Can I maybe set the default precision somewhere to 9 digits?
Well, I could think of some workaround to subtract the initial time...
but have I overlooked something?
Last edit: theozh 2021-02-09
I think I am failing to understand what plot you are trying to generate. It looks to me that variation 1 and variation 2 both produce the expected result, although variation 2 does require a cast from string to real:
If the intent is to add 3 decimal places of precision to the generated time data, maybe what you want is:
Sorry, for not providing a clearer example. Let me try again.
I want a histogram of time data in a table. (I guess your first example above will not work, see Example A below).
Code:
Results:
Version A:
smoothandwith tabledo not work togetherVersion B:
smoothandwith tabledo not work togetherVersion C:
smoothdoes not work together with time formatVersion D: all values =1.61292e+09 (because default formatting style is
%g, with 6 digits)Version E: explicit
set format x "%.0f"Version F: explicit
set format x "%Y-%m-%d %H:%M:%S" timedateConclusion:
So, I was missing to simply set the desired format in the table environment beforehand via
set format x .... But I cannot not set it within the plot command itself. No bug at all, just a misunderstanding. And the fact thatsmoothdoes not work together withwith tableis most likely an intended behaviour?!I would use
The intent of
with tableis to capture the input processing from theusingspecifier. All other plot properties are ignored, includingsmooth,variable,axes, etc.