Gnuplot 5.5自动轴范围失效,如何恢复旧版本绘图行为?
解决Gnuplot 5.5自动轴范围行为与旧版本不一致的问题
核心原因
Gnuplot 5.5(开发版)调整了自动轴范围的计算逻辑:当使用filledcurves x1/x2这类会延伸到轴边界的绘图样式时,默认会将轴范围扩展至绘图区域边界,而非仅基于数据点范围;同时手动设置轴范围时,默认不再自动给端点预留边距,导致数据端点被隐藏。
恢复旧版本自动轴范围行为的方法
1. 强制轴范围仅基于数据计算
在绘图前添加以下命令,让轴自动范围仅考虑数据文件中的实际数据点,忽略filledcurves等元素的边界延伸:
set autoscale x data set autoscale y data
若仅需调整x轴,保留set autoscale x data即可。
2. 手动设范围时保留端点边距
当手动指定轴范围(如plot [:35064.46][3.0145:3.5755])后,添加extend参数让Gnuplot自动给端点添加小边距,避免数据截断:
plot [:35064.46][3.0145:3.5755] extend ... # 后续保留原有绘图命令
也可提前设置全局轴边距:
set offset graph 0.02, 0.02, 0.02, 0.02 # 上下左右各留2%边距
3. 重置轴范围默认行为
若上述方法效果不佳,可直接恢复旧版本的轴范围计算逻辑:
set xrange [*:*] noreverse nowriteback set yrange [*:*] noreverse nowriteback
适配后的完整绘图命令示例
仅恢复自动数据范围的版本:
set autoscale x data plot [][3.0145:3.5755] 3.04 w filledcurves x1 fc rgb "#d9d9d9" notitle, \ 3.55 w filledcurves x2 fc rgb "#d9d9d9" notitle, \ for [i=1:11] 'gpdata.dat' every :::0::0 using 1:i+1 lt i+1 lw 3 ps 1.5 t word(elements,i) w linesp, \ 3.04 w lines lw 4 lt 1 lc rgb "red" t 'Допуск', 3.55 w lines lw 4 lt 1 lc rgb "red" notitle
手动设x轴上限且保留端点的版本:
set offset graph 0.01, 0.01, 0, 0 plot [:35064.46][3.0145:3.5755] extend 3.04 w filledcurves x1 fc rgb "#d9d9d9" notitle, \ 3.55 w filledcurves x2 fc rgb "#d9d9d9" notitle, \ for [i=1:11] 'gpdata.dat' every :::0::0 using 1:i+1 lt i+1 lw 3 ps 1.5 t word(elements,i) w linesp, \ 3.04 w lines lw 4 lt 1 lc rgb "red" t 'Допуск', 3.55 w lines lw 4 lt 1 lc rgb "red" notitle
内容的提问来源于stack exchange,提问作者Michael
相关产品推荐
相关产品推荐

