是否可以调整 gnuplot 的箱线图的高度?

Is it possible to adjust the height of the boxes plot of gnuplot?

以下是data.csv

#x,data
0,20
1,30
2,40
3,50

以下代码使用 gnuplot 绘制箱线图并保存为 png

import subprocess

proc = subprocess.Popen(['gnuplot','-p'], 
                        shell=True,
                        stdin=subprocess.PIPE,
                        encoding='utf8'
                        )

proc.communicate(
f"""
set terminal png size 400,300; set output 'plot.png';
set boxwidth 1
set style fill solid 1.0 
set xrange [-1:40]
set datafile separator comma 
plot 'data.csv' using 1:2 with boxes notitle

"""
)

输出的png图片:

是否可以修改每个盒子的高度,设置为10?

预期输出:

使用改编自 Object placement using a data file 的脚本,作者是伟大的 Hagen Wierstorf。

reset

# The range has to be set manually
set xrange [-1:5]
set yrange [10:70]

set datafile separator comma

set style rectangle dashtype solid fc rgb "#0077ff" fillstyle solid noborder

# Rectangle dimensions
height = 10
width = 1

# --- Read placement from data file
# Set the output of the following plot to a table in order to achieve that it is
# not shown in the current terminal
set table '/dev/null'
# Function to create the right call function
add_rectangle(x,y,hgt,wdt) = sprintf(\
    ' set object rect from "%f", "%f" to "%f", "%f"; ',x,y,x+wdt,y+hgt)
# Initialize command string
CMD = ''
# Do a dummy plot to read the position data
plot 'data.csv' u 1:(CMD = CMD.add_rectangle(,,height,width))
# Execute the drawing command
eval(CMD)
# Restore the terminal
unset table

# dummy empty plot to create the plot instance
plot x with line linecolor rgb"#ffffff" notitle

你可以得到这个情节

据我所知,您无法绕过手动设置绘图范围,但由于您使用的是 python 脚本来调用绘图,也许您可​​以将列的最小值和最大值传递给编写脚本并自动执行设置。

顺便说一句,有绘图风格with boxxyerror,检查help boxxyerror。 但是,从你的问题、你的草图和你给定的数据来看,你是否想要

并不完全清楚
  • 3盒;从一个数据点到下一个数据点(即高度 = 两个连续数据点之间的差异)
  • 4盒;从固定高度 10 的数据值开始。

代码:(第二个选项)

### plot boxes with defined height
reset session

$Data <<EOD
#x,data
0,20
1,30
2,40
3,50
EOD

set xrange [-1:40]
set datafile separator comma
set style fill solid 1.0
plot $Data u 1:2:(-0.5):(+0.5):2:(+10) w boxxyerror notitle

### end of code

结果: