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

Java调用GnuPlot绘图仅显示水平线问题求助

问题解决:GnuPlot绘制折线显示为水平线的修复

问题根源

你的数据使用逗号(,)作为小数点分隔符,但GnuPlot默认采用英文区域的小数点(.),导致程序无法正确解析数值,最终将所有Y轴值识别为相同的错误数值,呈现出水平线。

解决方案

在GnuPlot脚本中添加小数点分隔符的配置命令,让GnuPlot正确识别数据格式:

修改你的Java代码,在set datafile separator ";"之后添加set decimalsign ',':

try (PrintWriter writer = new PrintWriter(ficheiroComando)) {
                writer.write("set datafile separator \";\"\n");
                writer.write("set decimalsign ','\n"); // 新增:指定小数点为逗号
                writer.write("set size ratio 0.75\n");
                writer.write("set format x \"%.5f\"\n");
                writer.write("set terminal png\n");
                writer.write("set output '" + output + "'\n");
                writer.write("plot [0:30][0:1]'" + input + "' using 1:2 with lines title 'Suscetiveis' lc rgb 'red',\\\n");
                writer.write("'" + input + "' using 1:3 with lines title 'Infetados' lc rgb 'blue',\\\n");
                writer.write("'" + input + "' using 1:4 with lines title 'Recuperados' lc rgb 'green'\n");
            }

额外验证

  • 数据文件cleanOutput.txt每行末尾的分号不会影响解析,GnuPlot会自动忽略分隔符后的空列。
  • 可手动在GnuPlot终端执行以下片段,快速验证数值解析是否正常:
    set datafile separator ";"
    set decimalsign ','
    plot 'cleanOutput.txt' using 1:2 with lines
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 01:52:47