Gnuplot 无效命令“设置输出”
我已经尝试解决这个问题超过一天了,但是无论api(C++,python)和gnuplot版本不会,问题都是一样的。 让我们看一下几个不同的 python 代码示例,这些代码在 gnuplot 终端中无需 API 即可正常工作。
1.来自此处
from subprocess import Popen, PIPE
gnuplot = 'gnuplot'
p = Popen([gnuplot, '-persist'], stdin=PIPE)
cmd = b"""set terminal qt
set timefmt "%H:%M:%S"
set xdata time
set term png size 1600, 1200
set output "test.png"
set yrange [-1.5:1.5]
set grid
set title ("test_param");
plot "test.dat" using 1:2 with lines lt rgb "blue" lw 2 title "Q value"
"""
p.stdin.write(cmd); p.stdin.flush()
2.来自这里
import PyGnuplot as pg
pg.c("set terminal qt")
pg.c('set timefmt "%H:%M:%S";')
pg.c('set xdata time;')
pg.c('set yrange [-1.5:1.5]')
pg.c('set grid')
pg.c('plot "test.dat" using 1:2 with lines lt rgb "blue" lw 2 title "Q value"')
pg.c('set term png size 1600, 1200;')
pg.c('set output "test.png"')
在这两种情况下,我都会遇到一些奇怪的错误:
gnuplot> t output "test.png"
^
line 0: invalid command
我已经尝试了几乎所有 API 示例,但没有任何效果几乎相同的错误
“test.dat”示例:
00:00:05.742 -0.098281
00:00:05.745 -0.098281
00:00:05.746 -0.099969
00:00:05.747 -0.100051
00:00:05.748 -0.100051
00:00:05.749 -0.100037
00:00:05.750 -0.102142
00:00:05.750 -0.102150
00:00:05.752 -0.101780
I have been trying to solve the problem for more than a day, but whatever api (C++, python) and gnuplot version would not be, the problem is the same.
Let's look at several different examples of python code that works fine without an API in the gnuplot terminal.
1.From here
from subprocess import Popen, PIPE
gnuplot = 'gnuplot'
p = Popen([gnuplot, '-persist'], stdin=PIPE)
cmd = b"""set terminal qt
set timefmt "%H:%M:%S"
set xdata time
set term png size 1600, 1200
set output "test.png"
set yrange [-1.5:1.5]
set grid
set title ("test_param");
plot "test.dat" using 1:2 with lines lt rgb "blue" lw 2 title "Q value"
"""
p.stdin.write(cmd); p.stdin.flush()
2.From here
import PyGnuplot as pg
pg.c("set terminal qt")
pg.c('set timefmt "%H:%M:%S";')
pg.c('set xdata time;')
pg.c('set yrange [-1.5:1.5]')
pg.c('set grid')
pg.c('plot "test.dat" using 1:2 with lines lt rgb "blue" lw 2 title "Q value"')
pg.c('set term png size 1600, 1200;')
pg.c('set output "test.png"')
In both cases i get some strange error:
gnuplot> t output "test.png"
^
line 0: invalid command
I have tried almost all API examples and nothing works with almost the same errors
Example of "test.dat":
00:00:05.742 -0.098281
00:00:05.745 -0.098281
00:00:05.746 -0.099969
00:00:05.747 -0.100051
00:00:05.748 -0.100051
00:00:05.749 -0.100037
00:00:05.750 -0.102142
00:00:05.750 -0.102150
00:00:05.752 -0.101780
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我还没有完全理解所有细节,但以下内容对我有用(Python 3.6.3 Windows 10)。
与您的第一个代码示例有一些区别:
png
,为什么还要设置 term qt ?r'...'
,\\
(对于 Python?!)。或者,您可以仅使用单个前斜杠/
,例如set output 'C:/Users/W2102029/Scripts/test.png'
如果有更好的方法和解释,我我很高兴向更有经验的 Windows/Python/gnuplot 用户学习。
代码:
结果:
test.png
将在磁盘上创建,Although I haven't fully understood all the details, the following works for me (Python 3.6.3 Windows 10).
Some difference to your first code example:
png
directly afterwards?r'...'
in the Python code\\
(for Python?!). Alternatively, you could use only single foreslashs/
, e.g.set output 'C:/Users/W2102029/Scripts/test.png'
If there are better ways and explanations, I am happy to learn from more experienced Windows/Python/gnuplot users.
Code:
Result:
test.png
with the plot will be created on disk