0

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).

Example of a horizontal bar chart with 2 different data sets

Is this possible at all with Gnuplot? If not, which program can be used alternatively? Many thanks.

maij
  • 4,094
  • 2
  • 12
  • 28
  • Have you seen https://stackoverflow.com/a/62854722/7010554? Have you tried to adopt it to your needs? – maij Mar 30 '21 at 09:42
  • 1
    Of course this is possible with gnuplot! What have you tried so far? How does your input data look like? Looks like a duplicate of https://stackoverflow.com/q/66611401/7295599 or at least very similar. Please show some code and some own effort and we will be able to help you. – theozh Mar 30 '21 at 09:42
  • Both examples show only bars with a data set x1 and y1 and a single coordinate origin. However, we are looking for a solution to plot two data sets in a row. In the above example in the figure there is e.g. in the first row the data set x1=1.368.102 y1=USA as well as from the right the data set x2=14.0 and y2=Bosnien – Christian Hähnlein Mar 30 '21 at 20:01
  • @ChristianHähnlein is your problem solved? If yes, then please check the answer as accepted. Any feedback would be appreciated. – theozh Apr 28 '21 at 09:54

1 Answers1

2

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:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72