Gnuplot SVG输出质量问题:多余白线与空g标签解决诉求
解决Gnuplot SVG图表的两个问题
问题1:右侧纵轴旁多余白色竖线
这条竖线是坐标轴设置超出绘图范围或背景矩形边界不当导致的,可通过以下两步修复:
- 移除初始的
set ytics "0",3600,"86400"指令,后续do for循环已生成0-23点的纵轴刻度,该指令中86400超出了yrange [0:86399]范围,会触发多余边界绘制。 - 将背景矩形的坐标系从
graph改为screen,确保完全覆盖绘图区域且不超出:set object 1 rectangle from screen 0, screen 0 to screen 1, screen 1 behind fc rgbcolor 'white' fs noborder
问题2:SVG文件包含大量空<g>标签
空标签源于plot命令拆分了过多独立绘图项(每个filledcurve单独调用plot),可合并成对的filledcurve x1/x2来减少空标签:
原脚本中每对filledcurve x1和x2对应同一颜色的上下填充,可合并为单个filledcurve指令(使用using 1:col1:col2语法),大幅减少空标签生成。
完整修正后的脚本
set terminal svg size 1000,500 noenhanced set output "dose.svg" set xlabel "Päiväys" textcolor rgb "white" set label 1 'Clock value' at graph -0.08, graph 0.3 rotate set xdata time set locale "fi_FI.utf8" set timefmt "%m-%d" set xtics out set format x "%b" set title "Pimeysdiagrammi LL" font "arial, 20" set key off datafile="./f.data" set datafile missing NaN set yrange [0:86399] set ytics ("" 0) do for [y = 0:23] { set ytics add (sprintf("%d",y) (y*3600)) } set grid ytics lt 2 lc rgb "red" lw 1 set border lw 2 lc rgb "orange" set xtics textcolor rgb "white" set ytics textcolor rgb "white" set ylabel "Kello" textcolor rgb "white" set title textcolor rgb "white" set object 1 rectangle from screen 0, screen 0 to screen 1, screen 1 behind fc rgbcolor 'white' fs noborder plot datafile using 1:2:3 w filledcurve lc rgb "#BFD0FB", \ '' using 1:4:5 w filledcurve lc rgb "#7FA2F7", \ '' using 1:6:7 w filledcurve lc rgb "#3F74F3", \ '' using 1:8:9 w filledcurve lc rgb "#0046F0", \ '' using 1:10:11 w filledcurve lc rgb "#002EA0", \ '' using 1:12:13 w filledcurve lc rgb "#001750", \ '' using 1:14:15 w filledcurve lc rgb "black", \ '' using 1:16 w impulse lc rgb "green", \ '' u 1:17:((strcol(18) eq "New") ? ('UUSI'):NaN) w labels left font "Symbola,14" offset -0.5,0, \ '' u 1:17:((strcol(18) eq "Full") ? ('VANHA'):NaN) w labels left font "Symbola,14" offset -0.5,0
数据示例
1-25 33780 54120 33540 54300 33240 54600 33060 54840 29160 58680 25380 62520 21840 66000 0 71640 Full
内容的提问来源于stack exchange,提问作者Timppa
相关产品推荐
相关产品推荐

