2

I want to put the Y values over the top of bars of the histogram for the graph below: `

set style data histogram
#clustered
#set terminal wxt enhanced persist
set term post eps enhanced "Times-Roman, 14"
set output 'avg_waste.bmp'
set boxwidth 1.3
set grid
set auto y
set auto x

set style histogram clustered gap 1 title offset 1,0.25
set ylabel "\nAverage Resource Wastage\n\n\n" font "Times-Roman,25"
set xlabel "\nWorkflows\n" font "Times-Roman,25"
#set style fill solid noborder
set style fill pattern  border -1

set key at graph 0.2, 0.9
set key spacing 2 font "Times-Roman,18"
set xtics font ", 25"
set ytics font ", 25"


plot for [COL=2:3] 'avg_waste' using COL:xticlabels(1) title columnheader fs pattern 2 `

when I try to use labels, gnuplot gives the error Not enough columns for this style My data file is

 #WASTAGE   
        CRCH        HEFT
Cybershake  20.89       22.5785714286
LIGO        187.3228571429  199.5134285714
SIPHT       205.7514285714  210.3685714286
Montage     12.1485714286   12.7942857143
user3319015
  • 99
  • 1
  • 5

1 Answers1

3

One possibility would be to place those labels manually as for example:

reset
fontSpec(s) = sprintf("Times-Roman, %d", s)

set term post eps enhanced fontSpec(16)
set output 'avg_waste.eps'

set grid
set auto y
set auto x

ticsFont=fontSpec(16)
set xtics font ticsFont
set ytics font ticsFont

set ylabel "Average Resource Wastage" font fontSpec(25) offset char -1,0
set xlabel "Workflows" font fontSpec(25) offset 0,char -1

set style fill pattern border -1
set style data histograms
set boxwidth 1.0
set style histogram clustered gap 1

keyFont=fontSpec(18)
set key spacing 2 font keyFont
#using directly 'set key spacing 2 font fontSpec(18)' doesn't seem to work...

set key at graph 0.25, 0.9

fn(v) = sprintf("%.1f", v)

plot \
    for [COL=2:3] 'avg_waste' using COL:xticlabels(1) title columnheader fs pattern 2, \
    'avg_waste' u ($0-1-1./6):2:(fn($2)) w labels font fontSpec(14) offset char 0,0.5 t '' , \
    'avg_waste' u ($0-1+1./6):3:(fn($3)) w labels font fontSpec(14) offset char 0,0.5 t ''

Also, since you seem to want to use the titles taken from columnheaders, the script above assumes that the input data is of the form:

WASTAGE   CRCH        HEFT
Cybershake  20.89       22.5785714286
LIGO        187.3228571429  199.5134285714
SIPHT       205.7514285714  210.3685714286
Montage     12.1485714286   12.7942857143

i.e., the first line is not commented out.

This then produces: enter image description here

EDIT: As for the using specification ($0-1-1./6):2:(fn($2)), it's based on the fact that the individual "block" of bars are centered at integer coordinates 0,1,2, and 3. Now, with two blocks per group, the width of each block is 0.3 (2 blocks between the centers of each group + one empty one for the space). The column 0, $0, contains the 0-based index of a particular line in the data file so for example for the "Cybershake" line, it is equal to 1, thus the syntax ($0-1-1./6):2:(fn($2)) then tells Gnuplot to place a label generated by the function fn at coordinates -1./6,$2, i.e., on top of the left bar in the "Cybershake" group. Here, fn is used just as a "macro" to format an input floating point number via the sprintf function.

ewcz
  • 12,819
  • 1
  • 25
  • 47