Reputation: 293
I want to plot the following data(which is stored in "0-time.txt")
time_,value
23:59:58,1
23:59:59,2
00:00:00,3
00:00:01,4
00:00:02,5
00:00:03,6
00:00:04,7
00:00:05,8
00:00:06,9
00:00:07,10
00:00:08,11
00:00:09,12
by the following gnuplot script:
set term png size 800,600
set output "0-time.png"
set datafile separator comma
set grid
set x2tics 6
set mx2tics 3
set link x2
set autoscale xfix
set autoscale x2fix
plot "0-time.txt" skip 1 every 2 using ($0*2):(0):xticlabels(int
($0*2)%6==0 ? stringcolumn(1):''), "" using ($0):2 axes x1y1 title columnheader(2)
set output
The output plot is alright except that labels on x2-axis is wrong. Please see the attached figure. How to correct it?
Upvotes: 0
Views: 191
Reputation: 25734
Maybe something like this?
Code: (a bit cleaned up)
### special tics
reset session
$Data <<EOD
23:59:58,1
23:59:59,2
00:00:00,3
00:00:01,4
00:00:02,5
00:00:03,6
00:00:04,7
00:00:05,8
00:00:06,9
00:00:07,10
00:00:08,11
00:00:09,12
EOD
set term png size 800,600
set output "0-time.png"
set datafile separator comma
set grid
set xtics 2
set mxtics 3
set link x2
set x2tics
set autoscale xfix
set autoscale x2fix
plot \
$Data using ($0*2):(NaN):xtic(int($0)%3==0?strcol(1):"") every 2 notitle, \
"" using 0:2:x2tic(int($0+1)%6==1?strcol(2):"") w p pt 7 ps 2 lc rgb "red" notitle
set output
### end of code
Result:
Upvotes: 2
Reputation: 1630
In Gnuplot, the data index $0
starts with zero, which is why you see 0 as the first x2 tic. But you can change the link in this way
set link x2 via x+1 inverse x-1
and then the x2 axis will be shifted by one unit with respect to x. Then you just change which x2 tics to display,
set x2tics 1, 6
which will hide 0, 6, 12, etc and show 1, 7, 13, etc instead.
Upvotes: 1