I am referring this example to draw a bar chart. I like, the exact value to be displayed on top of each of the red bars.

Like, those numeric values that are circled in green,

enter image description here

My gnuplot code is,

set size 1, 1
set term png size 600, 400
set title "sk plot"
set output "figure.png"
set boxwidth 0.75
set style fill solid
set title "Population of Australian cities (millions), as of June 2012"
plot "population.dat"  using 2:xtic(1) with boxes

Population.dat contains,

Adelaide    1.277174
Brisbane    2.189878
Canberra    0.374658
Darwin      0.131678
Hobart      0.216959
Melbourne   4.246345
Sydney      4.667283

You can do this by adding a second plot of the same data (shown by the filename ""), using with labels to add text at the given x,y co-ordinate calculated from column 0, i.e. just the data index, and column 2 with an offset so the text sits above the box, ($2+.1).

plot "population.dat"  using 2:xtic(1) with boxes,\
  ""  using 0:($2+.1):(sprintf("%3.2f",$2)) with labels notitle

The sprintf reduces the text printed to just 2 decimal places.

You can move the key shown at the top of the plot to stop it interfering using set key top left, for example.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.