GNUPLOT - a histogram of two columns with values ​​over bars

yesteraday I made a similar question ( this one ). I could not display the value on top of the line in the gnuplot histogram. I lost a lot of time because I could not find really good documentation about this, and I can find similar problems on different sites.

I lost a lot of time with this, but, fortunately, someone gave me a solution. Now I have a similar problem with a two-bar histogram in which I have to put its value on top of both bars. I am very close, or this is what I think, but I can not get it to work properly. I change the script and regenerate the graph many times, but I'm not sure what I am doing.

script.sh

#!/usr/bin/gnuplot
set term postscript
set terminal pngcairo nocrop enhanced size 600,400 font "Siemens Sans,8"
set termoption dash
set output salida
set boxwidth 0.8 absolute
set border 1
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 font 'Siemens Sans-Bold,20'
set yrange [0.0000 : limite1] noreverse nowriteback
set y2range [0.0000 : limite2] noreverse nowriteback
show style line


set style line 1 lt 1 lc rgb color1 lw 1
set style line 2 lt 1 lc rgb color2 lw 1

## Last datafile plotted: "immigration.dat"
plot fuente using 2:xtic(1) ls 1 ti col axis x1y1, '' u 3 ls 2 ti col axis x1y2, '' u 0:2:2 with labels offset -3,1 , '' u 0:2:3 with labels offset 3,1

, . , , . , , . , script.

output.png

enter image description here

,

source.dat

"Momento" "Torre 1" "Torre 2" 
"May-16" 1500.8 787.8
"Jun-16" 1462.3 764.1
"Jul-16" 1311.2 615.4
"Ago-16" 1199.0 562.0
"Sep-16" 1480.0 713.8
"Oct-16" 1435.1 707.8

,

gnuplot -e "titulo='Energía consumida por torre (MWh)'; salida='output.png'; fuente='source.dat'; color1='#FF420E'; color2='#3465A4'; limite1='1800.96'; limite2='945.36'" script.sh

, , , - ?

.

+3
3

script , ti col - . ( set key auto columnheader, ).

  • y1 y2, ! - ...

  • , gnuplot , . offset char ( , ), script , .

x- 0 x. 1, ($0 - 1/6.0) (= 1/(2 * (numberOfTorres + gapCount))), - ($0 + 1/6.0):

set terminal pngcairo nocrop enhanced size 600,400 font ",8"
set output 'output.png'
set title 'Energía consumida por torre (MWh)' font ",20"
set boxwidth 0.8 absolute
set border 1
set style fill solid 1.00 border lt -1
set style histogram clustered gap 1 title textcolor lt -1
set style data histograms
set xtics border scale 1,0 nomirror autojustify norangelimit
unset ytics

set key off auto columnheader
set yrange [0:*]
set offset 0,0,graph 0.05,0

set linetype 1 lc rgb '#FF420E'
set linetype 2 lc rgb '#3465A4'
# dx = 1/(2 * (numberOfTorres + gap))
dx = 1/6.0

plot 'source.dat' using 2:xtic(1),\
     '' u 3,\
     '' u ($0 - dx):2:2 with labels,\
     '' u ($0 + dx):3:3 with labels

enter image description here

, , offset, :

plot 'source.dat' using 2:xtic(1),\
         '' u 3,\
         '' u ($0 - dx):2:2 with labels offset -1,1 ,\
         '' u ($0 + dx):3:3 with labels offset 1,1

enter image description here

, : , :

absoluteBoxwidth = 0.8
dx = 1/6.0 * (1 - absoluteBoxwidth)/2.0

plot 'source.dat' using 2:xtic(1),\
         '' u 3,\
         '' u ($0 - dx):2:2 with labels right offset 0,1 ,\
         '' u ($0 + dx):3:3 with labels left offset 0,1

enter image description here

script .

+3

: enter image description here

plot fuente using 3:xtic(1) ls 1 ti col axis x1y1, '' u 3 ls 2 ti col axis x1y2, '' u ($0-1):3:3 with labels offset -3,1 , '' u ($0-1):2:2 with labels offset 3,1

2 : . , script.sh bash script. gnuplot script, .

+1

The problem is the tab ti col. You have to put it in every option, including labels, and not just in bars. The correct code is:

plot fuente using 2:xtic(1) ls 1 ti col, '' u 3 ls 2 ti col, '' u 0:2:2 ti col with labels offset -3,1 , '' u 0:3:3 ti col with labels offset 3,1

And as the image is now displayed:

enter image description here

You can also avoid ti col, and here is what it will look like:

enter image description here

+1
source

All Articles