I guess I found the a way to get notification when the plot changes - it has a "__modified__" property that I can add listener to. However, if I call "print" from the handler, it doesn't work, giving a strange Ghostscript error. Any ideas?
function my_handler(h, dummy)
if (strcmp(get(h, "__modified__"), "off"))
disp 'saving snapshot...';
print(gcf, 'snapshot.png', '-debug', '-dpng', '-S640,480')
addlistener (gcf, "__modified__", @my_handler);
Ghostscript command: '/usr/bin/gs -dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r72x72 -dEPSCrop -sOutputFile="snapshot.png" /tmp/oct-eyO49W.eps'
gnuplot-pipeline: '/usr/bin/gs -dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r72x72 -dEPSCrop -sOutputFile="snapshot.png" /tmp/oct-eyO49W.eps ; rm /tmp/oct-eyO49W.eps'
GPL Ghostscript 9.10: Unrecoverable error, exit code 1
rm: cannot remove '/tmp/oct-eyO49W.eps': No such file or directory
---------- output begin ----------
Error: /undefinedfilename in (/tmp/oct-eyO49W.eps)
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
--dict:1178/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
----------- output end -----------
error: print: failed to print
error: called from:
error: /usr/share/octave/3.8.1/m/plot/util/private/__gnuplot_print__.m at line 165, column 7
error: /usr/share/octave/3.8.1/m/plot/util/print.m at line 423, column 14
error: my_handler at line 15, column 5
On Fri Feb 13 2015 at 1:53:40 PM Ben Abbott <address@hidden
On Wed Feb 11 2015 at 4:36:55 PM Ben Abbott <address@hidden
> On Feb 11, 2015, at 1:39 PM, Alex K <address@hidden> wrote:
> Is it possible to run a custom function every time any plot is changed? For example, when running `plot`, `axis` etc., if they modify a figure on the screen I would like to detect that and save it to a new file.
> I use gnuplot as backend, so any solution involving configuring gnuplot will also work for me.
If you can provide mode details, someone may have a more efficient solution … but for a general solution I’d add a listener to the figures “children” property.
See “help addlistener” to see how to do that.
Thanks for the reply! For more context, I'm trying to make octave auto-save plots to files on the disk every time they are updated. I've tried addlistener but it doesn't seem to work:
fprintf ("my_handler called\n");
addlistener (gcf, "children", address@hidden, "my string"})
the handler is not getting called.
Ok, that’s embarrassing. I get no error, and it doesn’t work for me either.
There are many examples of this working correctly in Octave’s sources. (take a look at the m-file code of plotyy or subplot for examples).
Does anyone see a problem with Alex’s example?