使用Common Lisp和Gnuplot从emacs顺序绘制数据

YBE*_*YBE 5 lisp plot gnuplot common-lisp sequential

假设我有一些数据(一个特定的向量).我可以使用Gnuplot按顺序逐个元素地绘制它,使得它看起来好像是通过监视器追踪的真实信号吗?

我知道我可以使用Common Lisp将整个数据写入文本文件,然后使用gnuplot我可以以批处理格式绘制它.我需要的是,我希望在数据顺序出现时对我的情节说明一点.

数据可能会在循环内生成,因此您可以将x轴视为整数值离散时间轴.所以在循环中如果数组的第一个元素生成为5,我想在我的绘图上加点(0,5).然后,如果第二个元素生成为3,我想在我的绘图上添加另一个点(1,7)(保留旧数据点).因此,当我遍历循环时,我按顺序绘制数据.

我使用emacs和Common Lisp用于我的目的,我想将这些数据绘制在这些工具中.如果除了Gnuplot之外还有其他选择,我想听听他们的意见.

如果这不容易实现,那么如果我可以通过一些Common Lisp命令运行Gnuplot命令文件,那将会很酷.

编辑:

根据人们在这个帖子下给出的建议,我写了一个使用cgn它的代码ltk.
现在我在屏幕上预先指定的位置打开两个x11窗口,然后进入循环.在循环中,每次打开流并将数据(以20 Hz采样的0.25 Hz的正弦和余弦波)写入带有:if-exists :append选项的文本文件trial.txt 并关闭流.然后在每次迭代时,我使用gnuplot通过format-gnuplot命令绘制整个数据.这段代码给了我两个预先指定的x和y范围的窗口,然后可以看到窗口中上述正弦波和余弦波的演变.
正如我之前所说,我没有强大的编程背景(我是一名电子工程师,不知何故使用常见的lisp结束),我很确定我的代码是非最优和不优雅的.如果你们有一些进一步的建议,更正等我真的很想听听他们.代码在这里:

(setf filename "trial.txt")
(setf path (make-pathname :name filename))
(setf str (open path :direction :output  :if-exists :supersede :if-does-not-exist :create))
(format str "~,4F ~,4F" -1 -1)
(close str)

;start gnuplot process
(start-gnuplot "/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot")

;set 2 x11 windows with the following properties
(format-gnuplot "cd ~S" "Users/yberol/Desktop/lispbox/code")
(format-gnuplot "set terminal x11 0 position 0,0")
(format-gnuplot "set xrange [0:10]")
(format-gnuplot "set yrange [-1:1]")
(format-gnuplot "unset key")
(format-gnuplot "set grid")

(format-gnuplot "plot ~S using 1" filename)
(format-gnuplot "set terminal x11 1 position 800,0")
(format-gnuplot "plot ~S using 2" filename) 

;write data into text 
(loop :for i :from 0 :to 10 :by (/ 1 20) :do
   (setf str (open path :direction :output  :if-exists :append :if-does-not-exist :create))
   (format str "~,4F ~,4F ~,4F ~%" i (sin (* 2 pi (/ 5 20) i)) (cos (* 2 pi (/ 5 20) i)))
   (close str)
   (format-gnuplot "set terminal x11 0")
   (format-gnuplot "plot ~S using 1:2 with lines" filename)
   (format-gnuplot "set terminal x11 1")
   (format-gnuplot "plot ~S using 1:3 with lines" filename)
   (sleep 0.1))
(close-gnuplot)
Run Code Online (Sandbox Code Playgroud)

非常感谢你.

Vse*_*kin 3

cgn是一个与 gnuplot 交互的通用 Lisp 解决方案,它使用LTK