Gnuplot.py在一个图上绘制多条线
我现在遇到一个问题,想用gnuplot py从一个文本文件中画多条线。单独画每条线都没问题,但当我想把两条线放在同一个图上时,只能画出一条线。
这是我的代码:
#!/usr/bin/env python
import Gnuplot
g = Gnuplot.Gnuplot()
g('set terminal png') # Output of graph will be .png
g('set output "' + "python_test.png" + '"') # Set the name of the output file
g('set term png size 1200, 800')
g('set lmargin 8')
g('set rmargin 4')
g('set tmargin 3')
g('set bmargin 3')
g('set xdata time')
g('set timefmt "%H:%M:%S"')
g('set format x "%H:%M:%S"')
title = "Python Test graph "
g('set title "' + title + '"')
g('set xlabel "Time (HH:MM:SS)"')
g('set ylabel "' + "quantity" + '"')
#g('set xrange [*:*]')
plot_cmd = "< head -n -1 "
datFile = "data.dat"
g('plot "' + plot_cmd + datFile + '" using 1:3' + ' title "' + "Line 1" +'" with lines')
g('plot "' + plot_cmd + datFile + '" using 1:5' + ' title "' + "Line 2" +'" with lines')
我已经能用gnuplot的plot命令画出多条线,但在用gnuplot py的时候就不行了。我需要用gnuplot py,因为我想通过我的Python脚本生成gnuplot图。
如果需要的话,这里有我的数据文件链接:链接
1 个回答
1
为了让它正常工作,我把这两行代码合并成了一行。
g('plot "' + plot_cmd + datFile + '" using 1:3' + ' title "' + "Line 1" +'" with lines')
g('plot "' + plot_cmd + datFile + '" using 1:5' + ' title "' + "Line 2" +'" with lines')
这是让我能够绘制多条线的代码:
g('plot "' + plot_cmd + datFile + '" using 1:3 with lines, "' + plot_cmd + datFile + '" using 1:5 with lines')
非常感谢乔治,他帮我找到了问题的解决办法!