是否可以调整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图片:

输出png是

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

预期产量:

在此处输入图片说明

Matias Agelvis

这个脚本改编自伟大的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($1,$2,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脚本来调用绘图,因此您可以将列的最小值和最大值传递给脚本并自动进行设置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章