I have some problems with reading my file in Gnuplot. For example, I have a file like this:
___________________________________________
'#current'
month followed retweeted mentioned replied
Jan 395 29 35 28
Feb 380 28 32 31
'#previous'
month followed retweeted mentioned replied
Jan 381 30 38 32
Feb 378 25 42 30
Mar 374 28 46 40
______________________________________________________
I need to read only the second block, which starts with tag "#previous". How can I do it? I tried this command:
plot "data.txt" index 'previous' using 3:xticlabel(1) axes x1y1 with lines linecolor rgbcolor "red",\
but it doesn't work. Any ideas?
Although this question is pretty old and not yet accepted and the OP asks in the comments about a gnuplot-only solution, let me give one.
It is a bit confusing what is called a block in gnuplot.
"Blocks" which can be addressed via index are separated by two (or more) empty lines.
"(sub)blocks" which can be addressed via every :::b::b are separated by exactly one empty line.
A few things which are not given in your script/data need to be clarified:
# plus <keyword>. e.g. #previous, but not '#previous'.Furthermore:
with lines will not show anything.
Whereas with linespoints will only show the points, not the lines.A solution your your (unchanged) data:
'#previous' using stats.with points and again with vectors connecting the points.Data: SO1648594.dat
___________________________________________
'#current'
month followed retweeted mentioned replied
Jan 395 29 35 28
Feb 380 28 32 31
'#previous'
month followed retweeted mentioned replied
Jan 381 30 38 32
Feb 378 25 42 30
Mar 374 28 46 40
______________________________________________________
Script: (works with gnuplot>=4.6.0, March 2012)
### plot starting from specific keyword
reset
FILE = "SO1648594.dat"
stats FILE u (strcol(1) eq "'#previous'" ? r0=column(-1) : 0) nooutput
set key noautotitle
set offsets 0.5,0.5,0.5,0.5
plot FILE u 0:3:xtic(1) every :::r0+1 w p pt 7 lc rgb "red", \
x1=y1=NaN '' u (x0=x1,x1=column(0)):(y0=y1,y1=$3):(x0-x1):(y0-y1) every :::r0+1 w vec nohead lc rgb "red"
### end of script
Result:

Actually, a better data format would be:
Data: SO1648594_2.dat
___________________________________________
#current
month followed retweeted mentioned replied
Jan 395 29 35 28
Feb 380 28 32 31
#previous
month followed retweeted mentioned replied
Jan 381 30 38 32
Feb 378 25 42 30
Mar 374 28 46 40
______________________________________________________
Then the script (with the same result as above) would be reduced to:
Script: (works with gnuplot>=4.6.0, March 2012)
### plot starting from specific keyword
reset
FILE = "SO1648594_2.dat"
set key noautotitle
set offsets 0.5,0.5,0.5,0.5
plot FILE u 3:xtic(1) index "previous" w lp pt 7 lc rgb "red"
### end of script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With