Reputation: 113
I tried to plot a data sheet like this by Gnuplot.
Area_height MIC PCC_SQRT
Power 0.734852672 0.618902589 1
"Powder size (D90)" 0.712130033 0.702902099 2
"Powder size (D50)" 0.712130033 0.384749485 2
"Powder size (D10)" 0.712130033 0.448956759 2
Speed 0.590181886 0.582894451 1
"Energy density" 0.519402585 0.598153661 1
Cr 0.44654505 0.584812588 4
Liquidus 0.44654505 0.584812588 3
Ni 0.44654505 0.584812588 4
Mn 0.44654505 0.584812588 4
Mo 0.44654505 0.584812588 4
Column 4 is used to define colors for the bar.
I plotted with the following commands:
set style data histograms
plot "new/Area_height_MIC_PCC_New.txt" using 0:2:4:xtic(1) \
with boxes lc variable fill pattern 1, "" using 0:3:4:xtic(1) \
with boxes lc variable fill solid 1
or
set style histogram clustered
plot "new/Area_height_MIC_PCC_New.txt" using 0:2:4:xtic(1) \
with boxes lc variable fill pattern 1, "" using 0:3:4:xtic(1) \
with boxes lc variable fill solid 1
but the figure I got is like this,
the bars in solid and in pattern are overlapped. This is not what I want. I want them displayed next to each other.
Can someone tell me what is the problem?
Upvotes: 1
Views: 694
Reputation: 26068
you almost had it. You have to shift the boxes in x-direction by some value. This you can do e.g. by ($0-0.2)
and ($0+0.2)
.
Code:
### box plot with color from column
reset session
$Data <<EOD
# Area_height MIC PCC_SQRT
Power 0.734852672 0.618902589 1
"Powder size (D90)" 0.712130033 0.702902099 2
"Powder size (D50)" 0.712130033 0.384749485 2
"Powder size (D10)" 0.712130033 0.448956759 2
Speed 0.590181886 0.582894451 1
"Energy density" 0.519402585 0.598153661 1
Cr 0.44654505 0.584812588 4
Liquidus 0.44654505 0.584812588 3
Ni 0.44654505 0.584812588 4
Mn 0.44654505 0.584812588 4
Mo 0.44654505 0.584812588 4
EOD
set xrange[-0.5:]
set yrange[0:]
set boxwidth 0.3
set xtics rotate by 45 right offset first 0.2
plot $Data u ($0-0.2):2:4:xtic(1) w boxes lc var fill pattern 1, \
'' u ($0+0.2):3:4 w boxes lc var fill solid 1.0
### end of code
Result:
Upvotes: 2