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

如何使用Gnuplot绘制单X轴对应多组Y值的图表?

用Gnuplot绘制多列CSV数据的曲线

默认情况下Gnuplot只会用第1列作为x轴、第2列作为y轴绘制单条曲线,要画出所有y1到y4的曲线,你需要在plot命令里明确指定每一列的对应关系:

方法一:手动指定每一列

先设置分隔符,再逐个指定曲线的数据源:

set datafile separator ','
# 替换成你的数据文件名
plot 'data.csv' using 1:2 title 'y1', \
     '' using 1:3 title 'y2', \
     '' using 1:4 title 'y3', \
     '' using 1:5 title 'y4'
  • ''表示复用前面指定的文件,不用重复写文件名
  • using 1:n表示以第1列为x轴,第n列为y轴
  • title用来设置每条曲线的图例名称

方法二:用循环简化命令

如果列数较多,用循环可以避免重复代码:

set datafile separator ','
plot for [i=2:5] 'data.csv' using 1:i title sprintf('y%d', i-1)
  • for [i=2:5]表示循环处理第2到第5列
  • sprintf('y%d', i-1)自动生成y1、y2这类图例名称

可选:自定义曲线样式

要是需要调整线条粗细、颜色,可以在每条曲线后面加样式参数:

set datafile separator ','
plot 'data.csv' using 1:2 title 'y1' with lines lw 2 lc rgb 'red', \
     '' using 1:3 title 'y2' with lines lw 2 lc rgb 'blue', \
     '' using 1:4 title 'y3' with lines lw 2 lc rgb 'green', \
     '' using 1:5 title 'y4' with lines lw 2 lc rgb 'orange'
  • lw 2设置线条粗细为2
  • lc rgb 'red'指定线条颜色为红色

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 18:43:16