【问题标题】:gnuplot histogram : negative values go down instead go upgnuplot histogram :负值下降而不是上升
【发布时间】:2020-06-29 13:50:23
【问题描述】:

我尝试使用 gnuplot 生成直方图。我有正面和负面的价值观。正值位于图表顶部,负值位于图表底部。 我想改变上下的基础 例如从 0 到 -100。

也许,这样做不是很好的图形类型?

我已经试过了:

gnuplot -e "set terminal png size 20000, 1500; set yrange [-100:*]; set title 'VU Meter 0'; set style data histogram; set style histogram clustered gap 1; set style fill solid 1 noborder ; 使用 2:xticlabels(1)" > out.png 绘制“testVUmeter0.tsv”

谢谢

【问题讨论】:

  • 我不太明白。如果您有 2 个 y 值,例如 5 和 -5,则第一个直方图将从 y=0 变为 y=5,第二个直方图将从 y=0 变为 y=-5。你想看什么?
  • @meuh 例如,我有两个值 3 和 -2。例如,我想查看从 -5 开始的 2 个值。目前,基数为 0。

标签: gnuplot histogram


【解决方案1】:

据我所知,绘图样式 histogramwith boxes 总是从 y=0 开始。 假设我正确理解了你的问题,你想改变这个零水平,例如到 -100。 只要您不需要高级直方图样式而只需要简单的框,一种可能的解决方案就是使用绘图样式with boxxyerror。与@meuh 的解决方案相比,在这里,gnuplot 会自动处理 y-tics。

代码:

### shift zero for boxes
reset session

$Data <<EOD
A   -20
B  -140
C   100
D  -340
E  +250 
F     0
EOD

myOffset = -100
myWidth = 0.8
set style fill solid 1.0

set arrow 1 from graph 0, first myOffset to graph 1, first myOffset nohead ls -1
set style textbox opaque

plot $Data u 0:2:($0-myWidth/2.):($0+myWidth/2.):(myOffset):2:xtic(1) w boxxyerror notitle, \
     '' u 0:2:2 w labels boxed notitle 
### end of code

结果:

【讨论】:

    【解决方案2】:

    您可以在每个点计算一个新的 y 值,同时考虑一些想要的偏移量。例如,将 bot=-20 设置为底部 y 值 -20,您可以参考 ($2-bot) 将 -5 转换为高于 0 的 -5-(-20)=15`。

    set terminal png size 400,300
    set output "out.png"
    set style data histogram
    set style histogram clustered gap 1
    set style fill solid 1 noborder
    bot=-20
    set yrange [0:*]
    set ytics  ("-10" -10-bot, "0" 0-bot, "10" 10-bot, "20" 20-bot, "30" 30-bot)
    plot "data" using (($2)-bot):xticlabels(1) notitle,  \
         ""  using 0:($2+3-bot):(sprintf("%d",$2)) with labels notitle
    

    有数据

    1 33
    2 44
    3 22
    4 -12
    

    给出情节:

    【讨论】:

      猜你喜欢
      • 2022-10-23
      • 1970-01-01
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      • 2019-08-14
      • 2013-11-20
      相关资源
      最近更新 更多