【问题标题】:gnuplot draw two plots on the same graph with single column datagnuplot 在同一张图上用单列数据绘制两个图
【发布时间】:2012-04-26 19:03:33
【问题描述】:

有两个数据文件,比如说data1.txt

31231
32312
32323
32323

data2.txt

32323
54223
32456
45321

我想在同一张图上绘制这两个图,我该如何使用gnuplot 来实现呢?非常感谢你。

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    您可以在一个带有两个datafile 参数的plot 命令中在同一个图表上获得两个图,用逗号分隔。比如

      plot [-1:5] 'data1.txt' with points, 'data2.txt' with points
    

    会给你这样的东西:

    【讨论】:

    • 如何画线?我试过plot 'data1', 'data2' with lines,但我得到了所有的点并且点都在0 x轴上。
    • with lines 仅适用于第二个数据文件。试试plot 'data1' with lines, 'data2' with lines。看起来gnuplot 无法在同一目录中找到文件data2
    • 我也试过plot 'data1', 'data2' with points,但无法得到你所得到的。所有的点都在 0 x 轴上,这是为什么呢?
    • 可能是 y 轴上的刻度错误,或者 gnuplot 无法读取正确的 'data1' 文件。
    • 如果你在linux上,你可以输入gnuplot命令! cat data1来查看文件的内容。
    【解决方案2】:

    这对我有用:

    reset 
    set term pngcairo
    set output 'wall.png'
    set xlabel "Length (meter)"
    set ylabel "error (meter)"
    set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
    set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
    set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
    set datafile separator ","
    set key
    set auto x
    set xtics 1, 2, 9
    set yrange [2:7]
    set grid
    
    set label "(Disabled)" at -.8, 1.8
    plot  "file1.csv" using 1:2 ls 1 title "one" with lines ,\
      "file2.csv" using 1:2 ls 2 title "two" with lines ,\
      "file3.csv" using 1:2 ls 3 title "three" with lines
    set output
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 2011-03-15
      • 2012-11-24
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多