Reputation: 37
I have a data file like this:
PS 105 169 169 169 68 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
GMQ 43 0 255 0 39 0 0 255 40 34 139 34 105 169 169 169 105 169 169 169 0 169 169 169
GL 81 0 255 0 40 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
CM_{1} 105 169 169 169 47 0 0 255 105 169 169 169 32 169 169 169 105 169 169 169 0 169 169 169
CM_{2} 105 169 169 169 44 0 0 255 105 169 169 169 105 169 169 169 105 169 169 169 0 169 169 169
P 105 169 169 169 105 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
MH 105 169 169 169 69 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
in which in the columns 2 6 10 14 18 22 the values to be plotted are reported while in the remaining ones there is the rgb code.
I would like to get a graphic like that,
while with the attached script the bars are superimposed:
What should I correct in the script?
This is the Gnuplot script:
set term pngcairo enhanced size 2560,2048 font "Arial,50"
set output "Hist.png"
set encoding utf8
unset title
set yrange [0.0:150.]
set style data histogram
set style histogram cluster gap 1
set style fill solid
set boxwidth 1.
set xtics format ""
set ylabel "Training Set size [-]"
set grid ytics lw 2
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
unset key
plot "Data.out" u ($0):($2):(0.5):(rgb($3,$4,$5)) :xticlabels(1) w boxes lc rgb variable,\
"" u ($0):($6):(0.5):(rgb($7,$8,$9)) :xticlabels(1) w boxes lc rgb variable,\
"" u ($0):($10):(0.5):(rgb($11,$12,$13)):xticlabels(1) w boxes lc rgb variable,\
"" u ($0):($14):(0.5):(rgb($15,$16,$17)):xticlabels(1) w boxes lc rgb variable,\
"" u ($0):($18):(0.5):(rgb($19,$20,$21)):xticlabels(1) w boxes lc rgb variable
reset
Thanks for the help you can give me.
Best regard.
Upvotes: 1
Views: 1389
Reputation: 25724
According to the gnuplot demo page (http://gnuplot.sourceforge.net/demo/histograms.html) clustered histograms should be plotted like this:
plot "Data.out" u 2:xtic(1), '' u 6, '' u 10, '' u 14, '' u 18
However, I haven't found a way to color the histogram bars individually depending on data from the datafile as you would like to. I got the impression that ... lc rgb var
is not working together with histogram style (but I could be wrong). Maybe someone can tell us.
Therefore, my suggestion for realizing the clustered histogram "manually" with the plotting style with boxes
. You define a sequence of your columns you want to plot ColSequence = "2 6 10 14 18"
and a few more functions to shorten the plot command.
Code:
### clustered histograms realized "manually" with boxes
reset session
unset title
unset key
$Data <<EOD
PS 105 169 169 169 68 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
GMQ 43 0 255 0 39 0 0 255 40 34 139 34 105 169 169 169 105 169 169 169 0 169 169 169
GL 81 0 255 0 40 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
CM_{1} 105 169 169 169 47 0 0 255 105 169 169 169 32 169 169 169 105 169 169 169 0 169 169 169
CM_{2} 105 169 169 169 44 0 0 255 105 169 169 169 105 169 169 169 105 169 169 169 0 169 169 169
P 105 169 169 169 105 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
MH 105 169 169 169 69 0 0 255 105 169 169 169 0 169 169 169 0 169 169 169 0 169 169 169
EOD
set ylabel "Training Set size [-]"
set yrange [0.0:150.]
set grid ytics lw 2
set style fill solid
set boxwidth 1.0
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
ColSequence = "2 6 10 14 18"
myBoxWidth = 0.8
Gap = 2
ColCount = int(words(ColSequence))
ColNo(n) = int(word(ColSequence,n))
Color(n) = rgb(column(n+1),column(n+2),column(n+3))
BoxOffset(n) = 1./(ColCount+Gap)*n - 0.5
plot for [i=1:ColCount] $Data u ($0+BoxOffset(i)):(column(ColNo(i))): \
(1./(ColCount+Gap)*myBoxWidth):(Color(ColNo(i))) w boxes lc rgb var, \
$Data u 0:(0):xtic(1) w boxes
### end of code
Result:
Upvotes: 1