2

I'm trying make simple histogram with this file '.dat'

Moment "Energy consumed (MWh)"
"Apr-16" 2011.4
"May-16" 1869.6
"Jun-16" 1899.0
"Jul-16" 1659.0
"Aug-16" 1740.6
"Sep-16" 1670.0

For this purpose I have written the following script

  #!/usr/bin/gnuplot
  set term postscript
  set terminal pngcairo nocrop enhanced size 700,700 font "arial,18"
  set termoption dash
  set output out
  set boxwidth 0.5 absolute
  set border 0
  set style fill   solid 1.00 border lt -1
  set key off
  set style histogram clustered gap 1 title textcolor lt -1
  set datafile missing '-'
  set style data histograms
  set xtics border in scale 0,0 nomirror autojustify
  set xtics  norangelimit
  set xtics ()
  unset ytics
  set title titulo
  set yrange [0.0000 : limite] noreverse nowriteback

  show style line
  set style line 1 lt 1 lc rgb color lw 1

  ## Last datafile plotted: "immigration.dat"
  plot fuente using (column(0)):2:xtic(1) title titulo ls 1 with boxes, '' using 0:2:2 with labels

In this case out is the output filename, titulo is the label that appears on the top of the image output, limite is the value that I use as biggest value on y-axi, and fuente is the source filename.

The result is this

enter image description here

I am trying display the values over the bar with some offset because I need the values over the bars and not inside the bars. I would need separate I am trying with code like:

plot fuente using (column(0)):2:xtic(1) title titulo ls 1 with boxes, '' using 0:($2 + 0.5):2 with labels

because I have seen many sites where they get it doing $2 + 0.5 but this it doesn't work for me.

What should I do? Please help me I am completly lost. Thanks in advance.

Luis González
  • 3,199
  • 26
  • 43

1 Answers1

2

Use the offset parameter for the with labels plotting styles. With this you can add a vertical offset which you specify e.g. in character or graph units:

plot fuente using 0:2:xtic(1) with boxes, '' using 0:2:2 with labels offset 0, char 1

Sidenote: Adding the constant value of 0.5 to the y-value (like $2 + 0.5) doesn't work for you, because the 0.5 is in units of the y-axis, and very small compared to your yrange.

Christoph
  • 47,569
  • 8
  • 87
  • 187