You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gnuplot折线图并排绘制蜡烛图的宽度、偏移与图例问题

Gnuplot 性能对比图绘制问题修复方案

Gnuplot 支持基于坐标轴尺度、终端尺寸的相对参数配置,无需手动换算像素值,你遇到的三个问题可按以下方案逐一修复。


问题1:蜡烛图宽度异常修复

你使用的set boxwidth 0.1 relative是基于x轴单分类间隔的相对宽度,但你的x轴是连续数值轴(size值跨度达数十万级),0.1的相对值对应实际宽度仅几十数据单位,在大跨度轴上会被压缩成细线。

  • 放弃relative宽度模式,先自动计算x轴相邻数据点的间隔,再按比例设置蜡烛图绝对宽度,适配任意x轴跨度:
# 计算前两个数据点的x轴间隔,作为刻度间距基准
stats 'size.csv' using 1 every ::::0 name "x0" nooutput
stats 'size.csv' using 1 every :::1::1 name "x1" nooutput
dx = x1_max - x0_max
# 蜡烛宽度设为刻度间隔的1/4,预留并排空间
set boxwidth dx*0.25 absolute

问题2:同刻度多算法蜡烛图重叠修复

你之前用$1±1的固定偏移完全不适配大跨度x轴,偏移量需要和x轴刻度间隔成比例,同时折线的x坐标必须和对应蜡烛图的偏移量保持一致,不能全部绘制在原始size坐标上:

# 三个算法的x轴偏移量,按间隔均匀排布,避免重叠
offset_gsp = -dx*0.3
offset_spam = 0
offset_prefix = dx*0.3

绘图时折线和对应蜡烛图使用相同偏移量,同时给蜡烛图配置和折线一致的线条样式,保证颜色统一。

问题3:图例显示混乱修复

set key autotitle columnhead会自动读取当前绘图语句引用的第一列表头作为图例名,你之前的蜡烛图语句没有加notitle参数,会把无关列的表头全部加入图例,造成混乱;另外原代码存在列号引用错误,误将median列当成avg列绘制折线。

  • 关闭自动表头图例,手动给三条平均折线指定图例名称,所有蜡烛图语句添加notitle参数,不参与图例生成。

完整修正后可运行代码

注意:代码已修正所有列号对应关系,蜡烛图的箱体对应第一、第三四分位数,须线对应最小、最大值,折线对应该算法的平均执行时间

set terminal png size 1024,1024
set bmargin 5
# 关闭自动表头图例,手动指定更可控
unset key autotitle columnhead
set key top left font ",10"

set datafile separator ","

# 定义三个算法的线条样式
set style line 1 \
    linecolor rgb '#00ff00' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5

set style line 2 \
    linecolor rgb '#0000ff' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5

set style line 3 \
    linecolor rgb '#ff0000' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5

set style fill empty

# 自动计算x轴刻度间隔,适配蜡烛宽度和偏移
stats 'size.csv' using 1 every ::::0 name "x0" nooutput
stats 'size.csv' using 1 every :::1::1 name "x1" nooutput
dx = x1_max - x0_max
set boxwidth dx*0.25 absolute
offset_gsp = -dx*0.3
offset_spam = 0
offset_prefix = dx*0.3

set output 'sizeExp.png'
plot 'size.csv' using ($1+offset_gsp):5 with lp ls 1 title "GSP_avg", \
     '' using ($1+offset_spam):11 with lp ls 2 title "SPAM_avg", \
     '' using ($1+offset_prefix):17 with lp ls 3 title "PREFIX_SPAN_avg", \
     '' using ($1+offset_gsp):3:6:2:7 with candlesticks whiskerbars ls 1 notitle, \
     '' using ($1+offset_spam):9:12:8:13 with candlesticks whiskerbars ls 2 notitle, \
     '' using ($1+offset_prefix):15:18:14:19 with candlesticks whiskerbars ls 3 notitle

如果你的x轴数据点不是均匀间隔,可以把dx替换为所有相邻点间隔的最小值,保证蜡烛图不会在刻度密集处重叠。


内容的提问来源于stack exchange,提问作者Jakub Peschel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 20:33:07