Reputation: 9
I would like to create a horizontal bar chart with Gnuplot that consists of 2 x-axes and 2 y-axes and 2 coordinate origins. The coordinate origin for dataset 1 x1/y1 should be in the upper left corner and the coordinate origin for dataset 2 x2/y2 in the lower right corner (see following figure).
Is this possible at all with Gnuplot? If not, which program can be used alternatively? Many thanks.
Upvotes: 0
Views: 337
Reputation: 25734
Since you seem to be a new gnuplot user (but not a new StackOverflow member, as such you should now that some code is expected), it might be difficult to adapt the linked answers from the comments to your requirements. The plotting style would be with boxxyerror
, check help boxxyerror
and for the axes assignment check help axes
.
Furthermore, to get your numbers "readable", I'm not aware that gnuplot has some general format for thousand separators, at least not for Windows, but apparently for Linux (see gnuplot: How to enable thousand separators (digit grouping)?).
Check the following example:
Code:
### two way horizontal bars (and thousand separators)
reset session
$Data1 <<EOD
USA 1368102
Russland 541353
Australien 403382
China 324068
Polen 222394
Vietnam 199876
Pakistan 176739
Mongolei 119426
Kanada 118270
Indien 38971
Deutschland 36500
Indonesien 27998
Serbien 13074
Brasilien 12587
Rumänien 9640
Kosovo 9262
Argentinien 7300
EOD
$Data2 <<EOD
"Bosnien \\& Herzegowina" 14.0
Thailand 14.9
Laos 15.9
Rumänien 23.6
Bulgarien 30.3
Griechenland 36.1
Serbien 37.5
Tschechien 39.2
Australien 45.1
Indien 45.3
USA 51.7
Polen 58.6
Indonesien 60.0
Russland 80.0
Türkei 85.0
China 150.0
Deutschland 166.3
EOD
set xrange [220:0]
set xtics nomirror
set x2range [0:2000000]
set x2tics () nomirror # remove x2tics do it manually later
set yrange [17:-1]
set ytics out
set y2range [17:-1]
set y2tics out nomirror
myBoxWidth = 0.8 # relative boxwidth
yLow(i) = i - myBoxWidth/2.
yHigh(i) = i + myBoxWidth/2.
unset key
set style fill solid 0.5
# simple workaround for thousand separators (only for integer number strings)
ThousandSep(s) = (_tmp= '', sum [_i=0:strlen(s)-1] (_i%3==0 && _i!=0 ? _tmp="'"._tmp : 0, \
_tmp=s[strlen(s)-_i:strlen(s)-_i]._tmp, 0), _tmp)
# manual x2tics with thousand separators
do for [i=0:1500000:300000] {
myX2tic = ThousandSep(sprintf('%.0f',i))
set x2tics add (myX2tic i)
}
set label 1 at second 600000, graph 0.7 "Bestand" left font ",20"
set label 2 at first 140, graph 0.4 "Jahres-\nförderung" left font ",20"
plot $Data1 u (0):0:(0):2:(yLow($0)):(yHigh($0)):ytic(1) axes x2y1 w boxxy lc rgb 0x8ffd8c, \
'' u 2:0:(ThousandSep(strcol(2))) axes x2y1 w labels left offset 1,0, \
$Data2 u (0):0:(0):2:(yLow($0)):(yHigh($0)):y2tic(1) axes x1y2 w boxxy lc rgb 0x8d7bde, \
'' u 2:0:2 axes x1y2 w labels right offset -1,0, \
### end of code
Result:
Upvotes: 2