【问题标题】:How do you plot horizontal bar charts with x1, y1 and x2, y2 axis in gnuplot?如何在 gnuplot 中绘制带有 x1、y1 和 x2、y2 轴的水平条形图?
【发布时间】:2021-03-29 19:51:50
【问题描述】:

我想用 Gnuplot 创建一个由 2 个 x 轴和 2 个 y 轴以及 2 个坐标原点组成的水平条形图。数据集 1 x1/y1 的坐标原点在左上角,数据集 2 x2/y2 的坐标原点在右下角(见下图)。

使用 Gnuplot 是否可以做到这一点?如果不是,可以替代使用哪个程序?非常感谢。

【问题讨论】:

  • 你见过stackoverflow.com/a/62854722/7010554吗?您是否尝试将其用于您的需求?
  • 当然这可以通过 gnuplot 实现!你试过什么了?您的输入数据如何?看起来像 stackoverflow.com/q/66611401/7295599 的副本,或者至少非常相似。请展示一些代码和一些自己的努力,我们将能够为您提供帮助。
  • 两个示例都只显示了数据集 x1 和 y1 以及单个坐标原点的条形图。但是,我们正在寻找一种解决方案来连续绘制两个数据集。在上图中的示例中,例如第一行数据集 x1=1.368.102 y1=USA 以及右侧数据集 x2=14.0 和 y2=Bosnien
  • @ChristianHähnlein 你的问题解决了吗?如果是,请检查答案是否已接受。任何反馈将不胜感激。

标签: gnuplot


【解决方案1】:

由于您似乎是一个新的 gnuplot 用户(但不是新的 StackOverflow 成员,因此您现在应该需要一些代码),可能很难根据您的要求调整来自 cmets 的链接答案。绘图样式为with boxxyerror,检查help boxxyerror 和轴分配检查help axes。 此外,为了让您的数字“可读”,我不知道 gnuplot 对千位分隔符有一些通用格式,至少对于 Windows 没有,但显然对于 Linux(请参阅gnuplot: How to enable thousand separators (digit grouping)?)。

检查以下示例:

代码:

### 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

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    相关资源
    最近更新 更多