3
votes

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"
2

2 Answers

1
votes

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

1
votes

As Christoph has already explained, the problem is caused by the - in your input data.
Therefore, the best and cleanest solution is to make LibreOffice display missing data differently.

However, everything worked fine for me when I mask the using COLUMNNUMBER part by using $COLUMNNUMBER. Hence, I changed the last line of your code to

plot 'test.csv' u ($2):xtic(1) t "Menge A", '' u ($3) t "Menge B", \
     '' u ($4) t "Menge C"

As you see, you can shorten using to u and title to t. Moreover, you should use :xtic(1) only for the first data set.
Here is my outoput enter image description here