Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GnuPlot: stacked histogram causes hovering bars

Tags:

gnuplot

since two days I am trying to solve this problem. The bars of this stacked histogram are not printed above each other. They are floating freely around.

Secondly, I only want to print any 5th xtic-label. I am using GnuPlot v 4.6 patchlevel 6.hovering bars in stacked bargraph

Here are the first data rows (generated with libreoffice):

05.06,-,-,1
06.06,3,-,0
07.06,12,-,3
08.06,0,5,4
09.06,7,2,0
10.06,86,2,1
11.06,31,4,1
12.06,17,1,0
01.07,1,7,1

Here comes the command set:

gnuplot> set datafile separator ','
gnuplot> set style data histogram
gnuplot> set style histogram rowstacked
gnuplot> set style fill solid border -1
gnuplot> set xlabel "Zeit"
gnuplot> set ylabel "Anzahl"
gnuplot> set yrange [0:250]
gnuplot> plot 'test.csv' using 2:xtic(1) title "Menge A",'' 
gnuplot> using 3:xtic(1) title "Menge B",''
gnuplot> using 4:xtic(1) title "Menge C"
like image 679
Herr Olsen Avatar asked Jun 11 '26 19:06

Herr Olsen


1 Answers

Gnuplot seems to get confused with - as only column content. Also a set datafile missing '-' doesn't help. You need a datafile with really empty fields, like

05.06,,,1
06.06,3,,0
07.06,12,,3

If you cannot get LibreOffice to save the data file properly you can use e.g. sed to process the file on-the-fly:

plot "< sed 's/-//g' test.csv" using 2:xtic(1), '' ...

(This works properly if you don't have negative values, which I suppose is the case).

To the second part: Instead of xtic(1) you can also put any expression which evaluates to a string inside of xtic, like

xtic(int($0)%5 == 0 ? strcol(1) : '')

This uses the string in the first column as xticlabel if the row number is a multiple of 5, otherwise an empty string:

set datafile separator ','
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set xlabel "Zeit"
set ylabel "Anzahl"
set yrange [0:*]
plot '< sed "s/-//g" test.csv' using 2:xtic(int($0)%5 == 1 ? strcol(1) : '') title "Menge A",\
     '' using 3 title "Menge B",\
     '' using 4 title "Menge C"

enter image description here

like image 136
Christoph Avatar answered Jun 15 '26 11:06

Christoph