Reputation: 15
I have the following piece of data (example):
#Time Data
07/22/2013 6286
07/22/2013 10695
07/22/2013 17868
07/22/2013 18880
07/22/2013 19206
07/22/2013 20365
07/22/2013 18459
07/11/2013 3420
07/11/2013 3256
I'd like to plot the date on the x-axis & the second column on the y-axis.
Under the condition it should only plot the rows where the date equals "07/22/2013".
this is what i tried:
set datafile separator " "
set xdata time
set timefmt "%m/%d/%Y"
set xrange ["07/21/2013" : "07/23/2013"]
set yrange [3000:21000]
set format x "%m/%d"
plot "test_date.txt" using (stringcolumn(1) eq "07/22/2013"? $1:1/0):2 w p title "spots" lc 7
As a result Gnuplot tries to plot the digram but no datapoints are set (seen in the following picture "Result")
Does anyone know why that is? Do i should use "timecolumn()" instead of "stringcolumn()"? if so, how would i do this?
I'd appreciate any hints.
Upvotes: 1
Views: 536
Reputation: 25888
I guess the problem is that $1
tries to extract a number and will only find 07
. If you press the Autoscale button on the terminal window you will see that there is some data, but not where you expect it "00:07"
.
A quick fix would be to replace $1
with timecolumn(1)
.
According to Ethan set xdata time
is a relict from earlier gnuplot versions (but it still works). I would do it like the following:
Code:
### time data plot with ternary filter
reset session
$Data <<EOD
#Time Data
07/22/2013 6286
07/22/2013 10695
07/22/2013 17868
07/22/2013 18880
07/22/2013 19206
07/22/2013 20365
07/22/2013 18459
07/11/2013 3420
07/11/2013 3256
EOD
myTimeFmt = "%m/%d/%Y"
set xrange[strptime(myTimeFmt,"07/21/2013"):strptime(myTimeFmt,"07/23/2013")]
set yrange [3000:21000]
set format x "%m/%d" time
plot $Data u (strcol(1) eq "07/22/2013" ? timecolumn(1,myTimeFmt):NaN):2 w p title "spots" lc 7
### end of code
Result:
Upvotes: 1