1

I would like to create a histogram with boxes using three pieces of data, first the number of iterations as the x-axis, then the execution time as the y-axis and finally the number of processes used.

I would like to see a bar for each number of processes used, and with a color specific to the value of the number of processes. How can I do this?

My test data is defined as:

"iterations" "processes" "time_execution"
1000 1 14
1000 2 10
1000 4 9
4000 1 60
4000 2 42
4000 4 45
7000 1 80
7000 2 70
7000 4 50

And here is my script so far, but I can't get it to place the three bars side by side:

set term svg
set output out.svg

set boxwidth 1
set style fill solid 1.00 border 0
set style histogram
set size ratio 0.8

set xlabel 'Number of iterations'
set ylabel offset 2 'Time execution in seconds'

set key left Right
set key samplen 2 spacing .8 height 3 font ',10'
set title 'Time execution per iterations and processus used'

plot test.data u 1:3:2 w boxes

Thanks!

Tom Solid
  • 2,226
  • 1
  • 13
  • 32

2 Answers2

2

I guess your data format doesn't fit the expected histogram format. Check the examples on the gnuplot homepage, although, I think the examples are too crowded which might be confusing and maybe the reason why there are so many histogram questions on SO.

If you modify your data format (see below) it will be easy to plot the histogram. You can probably use any format, but the effort to prepare the data will be higher (see for example here: Gnuplot: How to plot a bar graph from flattened tables).

Script:

### plotting histogram requires suitable input data format
reset session

$Data <<EOD
xxx     1    2    4
1000   14   10    9
4000   60   42   45
7000   80   70   50
EOD

set style histogram clustered gap 1
set style data histogram
set boxwidth 0.8 relative
set style fill solid 0.3

set xlabel 'Number of iterations'
set xtics out
set ylabel 'Time execution in seconds'
set grid x,y
set key top center title "Processors"
set offset 0,0,0.5,0

plot for [col=2:4] $Data u col:xtic(1) ti col
### end of script

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • Thanks for your answer, that's exactly what I wanted ! I thought there would be an easier way ... I'll change my data layout ! – infrahinium Apr 26 '22 at 14:43
0

You can use lc variable

plot test.data u 1:3:2 w boxes lc variable notitle

EDIT

notitle is not necessary, but it makes the plot seems better.

Tom Solid
  • 2,226
  • 1
  • 13
  • 32
  • It is indeed much better, is it now possible to put the bars side by side, rather than one on top of the other? Here is the result after having applied all your advice : https://ibb.co/wgB1Mfj Thanks in advance – infrahinium Apr 25 '22 at 18:31
  • After some research, it seems that `set style histogram cluster` is the option I'm looking for. But from what I read, this option is overwritten by the `plot ... with ...`. How can I combine the `histogram cluster` and `w boxes lc variable` options ? – infrahinium Apr 25 '22 at 19:05