Reputation: 21
Using Linux. I'm able to use the plot3 octave function without the figure freezing through the command line if I use the gnuplot toolkit. However, when running it from python, using the oct2py module, I can't seem to change the toolkit although it appears as available, so the plot3 figure loads but freezes instantly.
The octave code:
%works fine
>graphics_toolkit('gnuplot');
>graphics_toolkit
ans=gnuplot
>plot3([2,1],[5,2],[10,12]) %test
The python code:
>>>from oct2py import octave
>>>octave.availabe_graphics_toolkits()
Cell([['fltk','gnuplot']])
#try to change toolkit, doesnt seem to work
>>>octave.graphics_toolkit('gnuplot')
'fltk'
>>>octave.plot3([2,1],[5,2],[10,12]) #freezes upon loading
-23.804176753943704
Upvotes: 2
Views: 334
Reputation: 22245
The 'fltk' image isn't "frozen" exactly. It just needs to be made 'visible' (if not already), and possibly 'refreshed'. Note that saving will work fine too, even if it looks frozen.
E.g. this will make the picture usable.
from oct2py import octave
octave.eval( " plot3([2,1],[5,2],[10,12]) " )
octave.eval( " set( gcf, 'visible', 'on' ) " )
octave.eval( " refresh " )
Note that you may also have to 'close' the figure programmatically through octave, i.e.:
octave.eval( " close all " )
But otherwise as long as you refresh appropriately, fltk should work fine.
However, if you insist on using gnuplot, in theory you can specify that explicitly as a plot_backend
parameter in the octave.eval
command, e.g.
octave.eval( " plot3([2,1],[5,2],[10,12]) ", plot_backend="gnuplot" )
In practice, as you point out, I've found that oct2py has a bit of trouble resetting the toolkit from the first plot. However, for some reason, if you open a figure and close it, the backend will be respected from that point on. I.e. this worked for me:
from oct2py import octave
octave.eval( "figure" )
octave.eval( "close" )
octave.eval( "plot3([2,1],[5,2],[10,12])", plot_backend="gnuplot" )
I have no idea why trying to switch the toolkit from "within" octave doesn't work; presumably it has something to do with oct2py's internals not allowing this. This probably explains why oct2py's eval provides a more direct way of selecting this via a python parameter instead.
Upvotes: 1