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

gnuplot如何实现过两点且延伸至绘图边缘的直线绘制而非线段

gnuplot绘制延伸至绘图边界的直线解决方案

你只需要先基于给定的两个点推导直线方程,再将原始点和直线分开绘制即可,gnuplot绘制函数时会自动延伸到你设定的xrange边界,满足需求。

适配当前场景的修改后完整代码

data:
 x  y
 0  4
 1 -1 

reset
set terminal svg enhanced fname 'Times New Roman' rounded dashed standalone
set size ratio 1.0
set xrange[-2:3]
set yrange[-2:6]
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.0
# 分开绘制原始点和延伸直线
plot data with points ls 1, -5*x + 4 with lines ls 1 

通用自动计算方案(无需手动算斜率截距)

如果你的数据点需要频繁修改,可通过stats命令自动提取参数生成直线,避免手动计算:

# 新增部分:自动读取两点计算直线参数
stats data nooutput
x1 = STATS_min_x
y1 = STATS_pos_min_y
x2 = STATS_max_x
y2 = STATS_pos_max_y
k = (y2 - y1)/(x2 - x1)
b = y1 - k*x1

plot data with points ls 1, k*x + b with lines ls 1

内容的提问来源于stack exchange,提问作者147pm

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 22:18:01