8

Is it possible to create dynamic plots in Gnuplot? What I require for my purposes is that, as the data is generated through some loop, I will use gnuplot to put some marker on the x-y axis preserving the older ones. So somehow I will be able to observe the evolution of the data instead of just seeing the final batch result.

What I specially want is equivalent to "drawnow" command in MATLAB.

Although not totally related, right now I am using common lisp to generate the data in a loop and cgn in order to plot within lisp using gnuplot. (I can plot data in batch form inside common lisp using cgn which utilizes gnuplot)

Thank you very much in advance for your attention.

edit: I have a written a code in common lisp for this purpose. You can check it here :
Plotting data sequentially from emacs using Common Lisp and Gnuplot
This thread is however more general and asks dynamic plotting in gnuplot. Any suggestions are welcome.

Community
  • 1
  • 1
jkt
  • 2,538
  • 3
  • 26
  • 28
  • I've always used file-IO to communicate from lisp to MATLAB. I've never gotten great visualization functionality out of lisp directly. I'll be interested to see if anyone comes up with some better solutions here – Clayton Stanley Feb 18 '12 at 00:23
  • @claytonstanley, can you please check the link above. I would also like to see your lisp-MATLAB implementation since up to this date I have always used MATLAB for my purposes and if I can somehow give commands to MATLAB from lisp I would really like to see it. You can also send an email to me if you like. Thank you very much in advance. – jkt Feb 18 '12 at 19:03
  • Your link above looks like a great start. Much more dynamic than any sort of file-IO can probably get you. The file-IO solution I used was to just generate the data to plot in a txt file, and then fire off an m file to plot the data in that file. The route you are going with cgn seems much better; and keeps everything in common lisp; I don't have any experience with cgn, so I can't help there. If you really do want to use Matlab to do the plotting, some sort of more dynamic interface between lisp and Matlab is prob the right way to go. Sockets? I know lisp supports them well; not sure on MLAB. – Clayton Stanley Feb 18 '12 at 21:43
  • @claytontstanley, thanks for the reply. It would be really great for anybody if there was some kind of an interface through common lisp and MATLAB. I will check sockets too. – jkt Feb 19 '12 at 01:02
  • Found this StackOverflow post on Matlab & sockets: http://stackoverflow.com/questions/7626854/matlab-mex-socket-wrapper-library – Clayton Stanley Feb 19 '12 at 02:17

2 Answers2

1

Unfortunately it's not easy to plot single points in gnuplot, but luckily there are some simple hacks as discussed here: Plotting a Single Point with Gnuplot. The echo method discussed there will only work in a Unix environment though.

Using this with replot instead of plot in your program should hopefully give you a graph of points evolving with time that preserves the previous points.

Another way, which is what I use with python, is that I put the data points in a file. In every iteration, I add points to the file then plot with gnuplot again. It's a little ugly, but it does the job in most cases.

Abhranil Das
  • 5,702
  • 6
  • 35
  • 42
  • that's what I am doing right now. Using common lisp I am adding a single point to a text file, then plotting it. The issue is obviously as text file gets bigger, the time for plotting at each time step gets slower. – jkt Apr 20 '12 at 02:33
0

I'm not sure that I completely understand what you are asking, but if you're looking to add a plot to the last string you plotted (and you're using gnuplot 4.4), the following does the trick:

gnuplot> plot sin(x),cos(x)  #plot sin and cos in an xterm window
gnuplot> eval GPVAL_LAST_PLOT."cos(x+pi/2.5)"  #add cos(x+pi/2.5) to the current plot

Anyway, I'm not sure if that's what you're asking for as I don't use Matlab, but I hope it is.

mgilson
  • 300,191
  • 65
  • 633
  • 696