|
From: theozh <th...@gm...> - 2016-07-15 14:12:55
|
Horizontal bar graphs seem to be a recurrent question.
In contrast to vertical bar graphs and histograms, as far as I know
there is no direct command in gnuplot for creating horizontal ones. I do
not know why. It really would be convenient.
A somewhat cumbersome workaround does it with boxxyerrorbars.
If your file "Test.dat", e.g. looks like the following:
# Col1 Col2 Col3 Legend
5 7 12 ItemA
8 8 14 ItemB
12 24 2 ItemC
3 2 7 ItemD
Make sure that in the following code there is no newline, except after '\'.
The first plot is in absolute values, the second plot in percentage
values. The legend is written as axis tics.
#### horizontal histogram
reset
set multiplot layout 2,1
plot 'Test.dat' \
u (0):($0):(0):($1):($0-0.4):($0+0.4):ytic(4) axes x1y1 with
boxxyerrorbars fs solid lc rgb "red" notitle,\
'' u (0):($0):($1):($1+$2):($0-0.4):($0+0.4):ytic(4) axes x1y1 with
boxxyerrorbars fs solid lc rgb "green" notitle,\
'' u (0):($0):($1+$2):($1+$2+$3):($0-0.4):($0+0.4):ytic(4) axes x1y1
with boxxyerrorbars fs solid lc rgb "blue" notitle,\
plot 'Test.dat' \
u (0):($0):(0):(($1)/($1+$2+$3)):($0-0.4):($0+0.4):ytic(4) axes x1y1
with boxxyerrorbars fs solid lc rgb "red" notitle,\
'' u
(0):($0):(($1)/($1+$2+$3)):(($1+$2)/($1+$2+$3)):($0-0.4):($0+0.4):ytic(4)
axes x1y1 with boxxyerrorbars fs solid lc rgb "green" notitle,\
'' u
(0):($0):(($1+$2)/($1+$2+$3)):(($1+$2+$3)/($1+$2+$3)):($0-0.4):($0+0.4):ytic(4)
axes x1y1 with boxxyerrorbars fs solid lc rgb "blue" notitle,\
unset multiplot
|