1

I want to do several Row-stacked in a histogram like down below

Gnuplot Histogram Cluster (Bar Chart) with One Line per Category

I choose the first solution but I have something different because my x-axis is log scale, and the histogram will go the wrong position.

If I do my plot without log scale , it will be correct. without log but if I use log, the plot is not I want. log-version

Here is my data and code

cat shared_improve.txt
#   N       Sort         Build
2       0.0415      0.0203
4       0.0422      0.0231
8       0.0426      0.0217
16      0.0422      0.0206
32      0.0436      0.0214
64      0.0431      0.0238
128     0.0687      0.0276
256     0.3207      0.0277
512     0.0434      0.0318
1024    0.3241      0.0498
2048        0.2156      0.0756
4096        0.2206      0.1104
8192        0.5088      0.1803
16384       0.5429      0.3554
32768       0.2683      0.6023
65536       0.2916      1.1679
131072      0.2424      1.9058
262144      0.2779      2.1457
524288      0.3869      3.8198
1048576     0.4464      7.6622
2097152     0.6034      15.146
4194304     0.9236      30.152
8388608     1.6020      61.129
16777216    2.8925      120.464     
33554432    5.5434      239.922
cat global_improve.txt 
#   N       Sort        Build
2       0.0747      0.0201
4       0.0702      0.0170
8       0.0880      0.0260
16      0.0608      0.0162
64      0.0623      0.0186
128     0.0659      0.0211
256     0.3593      0.0212
512     0.0567      0.0240
1024        0.3552      0.3038
2048        0.5106      0.0370
4096        0.5349      0.0590
8192        0.5215      0.0920
16384       0.5965      0.1671
32768       0.5179      0.2886
65536       0.5216      0.5452
131072      0.2529      1.2914
262144      0.5777      2.4295
524288      0.7484      4.3674
1048576     0.8304      8.5765
2097152     1.1448      17.0458
4194304     1.8410      36.0509
8388608     3.1218      67.5819
16777216    5.8081      138.0298

reset

set terminal png font " Times_New_Roman,12 "
set output "test.png"

set logscale x 2
set xtics 2
set xtics rotate out
set style fill solid border -1

set boxwidth 0.3/2
dx=0.5/2
offset=-0.1
set yrange[0:0.5]

plot  [1:16]'shared_improve.txt' using ($1+offset):($2+$3) title "sort shared" linecolor rgb "#cc0000" with boxes  ,\
    ''         using ($1+offset):3 title "build shared" linecolor rgb "#ff0000" with boxes ,\
      'global_improve.txt' using ($1+offset+dx):($2+$3) title "sort global" linecolor rgb "#00cc00" with boxes ,\
    ''         using ($1+offset+dx):3  title "build global" linecolor rgb "#00ff00" with boxes

石允齊
  • 21
  • 3

1 Answers1

0

If you draw the boxes and set the offsets yourself you have to take into account the log-scale. There, to get constant offsets you don't have to add or substract a value but multiply or divide by some value.

Code:

reset

set terminal png font "Times_New_Roman,12"
set output "test.png"
set key top left

set logscale x 2
set xtics 2
set xtics rotate out
set style fill solid border -1

set boxwidth 0.3
offset=1.15

plot  [1.1:1500] \
    'shared_improve.txt' u ($1/offset):($2+$3) w boxes lc rgb "#cc0000" ti "sort shared", \
    '' u ($1/offset):3 w boxes lc rgb "#ff0000" ti "build shared", \
    'global_improve.txt' u ($1*offset):($2+$3) w boxes lc rgb "#00cc00" ti "sort global",\
    '' u ($1*offset):3 w boxes lc rgb "#00ff00" ti "build global" 
set output

Result:

(some values at 32 are (un?)intentionally missing?)

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72