On Mon, 4 Apr 2016, Artur T. wrote:
Dear gretl users,
I know that this is actually a gnuplot-issue but I thought that some of
may also be interested in it and I somebody else could help me with this.
I would like to generate a clustered histogram in the same vein as the
2nd one here:
http://gnuplot.sourceforge.net/demo_svg_5.0/histograms.html
using gnuplot version 5.
However, my example function below doesn't produce the graph I need, as
only the first column (first bar) is plotted but not the 2nd one. I
already spent a while on this but couldn't find the error.
<hansl>
clear
set echo off
set messages off
set seed 1234
function void plotty (matrix mat, string fname)
string path = "barclust.gp"
sprintf tmpfile "@dotdir/@path"
outfile @tmpfile --write
printf "set encoding utf8 \n"
printf "set auto x \n"
printf "set style data histogram \n"
printf "set style histogram cluster gap 1 \n"
printf "set style fill solid border -1 \n"
printf "set boxwidth 0.9 \n"
printf "plot '-' using 2:xtic(1), '' using 3\n"
loop i=1..rows(mat) -q
loop j=1..cols(mat) -q
if mat[i,j]<0 || mat[i,j]>=0
printf "%.6f", mat[i,j]
else
printf "NaN"
endif
if j<cols(mat)
printf " "
endif
endloop
printf "\n"
endloop
printf "e \n"
outfile --close
gnuplot --input="@tmpfile" --output="@fname"
end function
matrix mat = seq(1,5)'~mnormal(5,2)
string fname = "(a)dotdir/check.pdf"
plotty(mat, fname)
The relevant portion of your .gp file looks like this:
plot '-' using 2:xtic(1), '' using 3
1.000000 -1.592375 -0.718122
2.000000 -0.578145 -1.755611
3.000000 1.781512 1.687621
4.000000 0.637465 -1.216122
5.000000 -0.882900 0.479029
e
If you're using the "trailing inline data" mode that's supported in
gnuplot 4 (as well as 5), it should look like the following, with a
data block for each individual comma-separated plot clause:
plot '-' using 2:xtic(1), '-' using 1
1.000000 -1.592375
2.000000 -0.578145
3.000000 1.781512
4.000000 0.637465
5.000000 -0.882900
e
-0.718122
-1.755611
1.687621
-1.216122
0.479029
e
If using the new inline data mode of gnuplot 5, it should look like:
$mydata << EOD
1.000000 -1.592375 -0.718122
2.000000 -0.578145 -1.755611
3.000000 1.781512 1.687621
4.000000 0.637465 -1.216122
5.000000 -0.882900 0.479029
EOD
plot $mydata using 2:xtic(1), '' using 3
(More compact, but won't work with gnuplot 4.)
Allin