GNUPLOT - Two columns histogram with values on top of bars -


yesteraday made similar question (this one). not display value on top of bar in gnuplot histogram. lost many time because couldn't find documentation it, , can find similar issues on differents websites.

i lost many time fortunately give me solution. having similar issue histogram 2 bars, in have put on top of both bars value. quite near, or think, can't make work properly. changing script , regenerating graph many times not sure of 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 labels offset -3,1 , '' u 0:2:3 labels offset 3,1 

i modifying last code line, because here set labels. have been able show both labels, in bad positions, have been able show 1 of labels in right position no other. have been able show thing want. graph generates script.

output.png

enter image description here

this source file use generating graph

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 

and that's command execute parameters set

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 

i think quite obvious pretending, can me?

lots of in advance.

your script has several problems, missing ti col 1 of them. (you can use set key auto columnheader, must not give option every time).

  • don't use both y1 , y2 axis if want compare values! otherwise correct bar heights matter of luck...

  • understand, how gnuplot positions histogram bars, can locate top center of each bar. if use offset char values (which case when give numbers), script break add or remove data row.

the histogram clusters start @ x-position 0, , positioned centered @ integer x values. since have 2 bars in each cluster , gap of 1, center of first bar @ ($0 - 1/6.0) (= 1/(2 * (numberoftorres + gapcount))), second 1 @ ($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 labels,\      '' u ($0 + dx):3:3 labels 

enter image description here

now, starting @ bars center can safely use offset specify offset relative bars top center:

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

enter image description here

a second option use label's alignment: labels of red bars right aligned @ bars right border, labels of blue bars left aligned @ bars left border:

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 labels right offset 0,1 ,\          '' u ($0 + dx):3:3 labels left offset 0,1 

enter image description here

in case, both options make script more robust against changes of input data.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -