Gnuplot,直方图中的条形重叠,无法分开,为什么

时间:2019-05-28 21:25:23

标签: gnuplot histogram overlap

我试图通过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

第4列用于定义条形的颜色。

我使用以下命令进行绘制:

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

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

但是我得到的数字是这样的,

output

实心和图案中的条重叠。这不是我想要的。我希望它们彼此相邻显示。

有人可以告诉我是什么问题吗?

1 个答案:

答案 0 :(得分:1)

您几乎拥有了。您必须将框沿x方向移动一些值。您可以这样做,例如由($0-0.2)($0+0.2)来完成。

代码:

### 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

结果:

enter image description here