gpt4 book ai didi

GNUPLOT - 两列直方图,条形顶部有值

转载 作者:行者123 更新时间:2023-12-05 00:17:19 26 4
gpt4 key购买 nike

昨天我提出了一个类似的问题( this one )。我无法在 gnuplot 直方图中显示条形顶部的值。我失去了很多时间,因为我找不到关于它的真正好的文档,而且我只能在不同的网站上找到类似的问题。

我失去了很多时间,但幸运的是有人给了我解决方案。现在,我在带有两个条形的直方图上遇到了类似的问题,其中我必须将其值放在两个条形之上。我很接近,或者这就是我的想法,但我无法使其正常工作。我多次更改脚本并重新生成图表,但我不确定我在做什么。

脚本.sh

#!/usr/bin/gnuplot
set term postscript
set terminal pngcairo nocrop enhanced size 600,400 font "Siemens Sans,8"
set termoption dash
set output salida
set boxwidth 0.8 absolute
set border 1
set style fill solid 1.00 border lt -1
set key off
set style histogram clustered gap 1 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror autojustify
set xtics norangelimit
set xtics ()
unset ytics
set title titulo font 'Siemens Sans-Bold,20'
set yrange [0.0000 : limite1] noreverse nowriteback
set y2range [0.0000 : limite2] noreverse nowriteback
show style line


set style line 1 lt 1 lc rgb color1 lw 1
set style line 2 lt 1 lc rgb color2 lw 1

## Last datafile plotted: "immigration.dat"
plot fuente using 2:xtic(1) ls 1 ti col axis x1y1, '' u 3 ls 2 ti col axis x1y2, '' u 0:2:2 with labels offset -3,1 , '' u 0:2:3 with labels offset 3,1

我正在修改最后一行代码,因为我在这里设置标签。我已经能够显示两个标签,但是在错误的位置,我也能够在正确的位置显示一个标签,但没有显示另一个。我已经能够展示几乎所有东西,但我想要的东西。这是生成脚本的图形。

output.png

enter image description here

这是我用于生成图形的源文件

source.dat
"Momento" "Torre 1" "Torre 2" 
"May-16" 1500.8 787.8
"Jun-16" 1462.3 764.1
"Jul-16" 1311.2 615.4
"Ago-16" 1199.0 562.0
"Sep-16" 1480.0 713.8
"Oct-16" 1435.1 707.8

这就是我使用参数集执行的命令
gnuplot -e "titulo='Energía consumida por torre (MWh)'; salida='output.png'; fuente='source.dat'; color1='#FF420E'; color2='#3465A4'; limite1='1800.96'; limite2='945.36'" script.sh

我认为这很明显我在假装,有人可以帮助我吗?

非常感谢提前。

最佳答案

你的脚本有几个问题,缺少ti col只是其中之一。 (您也可以使用 set key auto columnheader ,那么您不能每次都给出该选项)。

  • 不要同时使用 y1y2轴如果你想比较值!否则正确的条形高度只是运气问题...
  • 了解 gnuplot 如何定位直方图条,然后您可以准确定位每个条的顶部中心。如果您只使用 offsetchar值(当您只提供数字时就是这种情况),那么一旦您添加或删除数据行,您的脚本就会中断。

  • 直方图簇从 x 位置开始 0 , 和以整数 x 值为中心定位。由于每个集群中有两个条形且间隙为 1,因此第一个条形的中心位于 ($0 - 1/6.0) (= 1/(2 * (numberOfTorres + gapCount))),第二个在 ($0 + 1/6.0) :
    set terminal pngcairo nocrop enhanced size 600,400 font ",8"
    set output 'output.png'
    set title 'Energía consumida por torre (MWh)' font ",20"
    set boxwidth 0.8 absolute
    set border 1
    set style fill solid 1.00 border lt -1
    set style histogram clustered gap 1 title textcolor lt -1
    set style data histograms
    set xtics border scale 1,0 nomirror autojustify norangelimit
    unset ytics

    set key off auto columnheader
    set yrange [0:*]
    set offset 0,0,graph 0.05,0

    set linetype 1 lc rgb '#FF420E'
    set linetype 2 lc rgb '#3465A4'
    # dx = 1/(2 * (numberOfTorres + gap))
    dx = 1/6.0

    plot 'source.dat' using 2:xtic(1),\
    '' u 3,\
    '' u ($0 - dx):2:2 with labels,\
    '' u ($0 + dx):3:3 with labels

    enter image description here

    现在,从酒吧中心开始,您可以安全地使用 offset仅指定相对于条形顶部中心的偏移量:
    plot 'source.dat' using 2:xtic(1),\
    '' u 3,\
    '' u ($0 - dx):2:2 with labels offset -1,1 ,\
    '' u ($0 + dx):3:3 with labels offset 1,1

    enter image description here

    第二种选择是使用标签的对齐方式:红色条的标签在条的右边界处右对齐,蓝色条的标签在条的左边界处左对齐:
    absoluteBoxwidth = 0.8
    dx = 1/6.0 * (1 - absoluteBoxwidth)/2.0

    plot 'source.dat' using 2:xtic(1),\
    '' u 3,\
    '' u ($0 - dx):2:2 with labels right offset 0,1 ,\
    '' u ($0 + dx):3:3 with labels left offset 0,1

    enter image description here

    在任何情况下,这两个选项都可以使您的脚本对输入数据的更改更加健壮。

    关于GNUPLOT - 两列直方图,条形顶部有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40484582/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com