Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error plotting with Octave 6.1.0 on jupyter notebook #183

Closed
foxserie opened this issue Dec 31, 2020 · 5 comments · Fixed by #204
Closed

Error plotting with Octave 6.1.0 on jupyter notebook #183

foxserie opened this issue Dec 31, 2020 · 5 comments · Fixed by #204

Comments

@foxserie
Copy link

I have installed two versions of Octave both 32 bits.

  • Octave 4.4.1 that was the one I used the most and
  • Octave 6.1.0 that is the most recent one.

*I also have gnuplot 5.2 patch level 7 installed-

The octave kernel is installed in anaconda via:

conda install octave_kernel

  • to know where to look for the executable in windows you require the enviromental variable, here i tell it to go for Octave-4.4.1:

OCTAVE_EXECUTABLE
C:\\Octave\\Octave-4.4.1\\bin\\octave-cli.exe

once it's up and running, the jupyter notebook loads the kernel and i run the example:

x=-10:0.1:10+eps;
y=-10:0.1:10+eps;

[xx,yy]=meshgrid(x,y);

zz= sin(sqrt(xx.^2+yy.^2))./(sqrt(xx.^2+yy.^2));

surf(xx,yy,zz)
view(-35,45)
shading interp

resultant plotting from the code above

If I check the graphic toolkits that display the plots with the commands i get:

available_graphics_toolkits()

    ans =
    {
      [1,1] = fltk
      [1,2] = gnuplot
    }

And the current toolkit is:

loaded_graphics_toolkits ()

    ans =
    {
      [1,1] = gnuplot
    }

BUT if i change the enviromental variable to point to the Octave-6.1.0 executable with: C:\\Octave\\Octave-6.1.0\\mingw32\\bin\\octave-cli.exe

once i run the chunks of code, the ones with calculations are doing fine

x=-10:0.1:10+eps;
y=-10:0.1:10+eps;

[xx,yy]=meshgrid(x,y);

zz= sin(sqrt(xx.^2+yy.^2))./(sqrt(xx.^2+yy.^2));

for example, if i take the ; off the zz variable you get the matrix printed on the output

zz =

 Columns 1 through 6:

   7.0710e-02   7.0912e-02   7.0764e-02   7.0268e-02   6.9428e-02   6.8251e-02
   7.0912e-02   7.0761e-02   7.0254e-02   6.9397e-02   6.8194e-02   6.6655e-02
   7.0764e-02   7.0254e-02   6.9386e-02   6.8166e-02   6.6601e-02   6.4702e-02
   7.0268e-02   6.9397e-02   6.8166e-02   6.6583e-02   6.4658e-02   6.2404e-02
   6.9428e-02   6.8194e-02   6.6601e-02   6.4658e-02   6.2378e-02   5.9773e-02
   6.8251e-02   6.6655e-02   6.4702e-02   6.2404e-02   5.9773e-02   5.6826e-02 ...

 .... etc.

but the plot block of code

surf(xx,yy,zz)
view(-35,45)
shading interp

sends as output the error:

Inline plot failed, consider trying another graphics toolkit
error: print: figure must be visible or qt toolkit must be used with __gl_window__ property 'on' or QT_OFFSCREEN feature available
error: called from
    _make_figures>safe_print at line 125 column 7
    _make_figures at line 49 column 13

Which tells me there is somwthing between jupyter kernel and Octave 6.1.0, maybe Octave handles graphics in a new way?.

I know Octave 6.1.0 is working because the same code produces the correct plot if you run it directly in the octave application gui or cli.

plot window of the same graph captured from the Octave-gui application


The octave kernel says it's working if I check it with the command

python -m octave_kernel.check

The check reveals:

Octave kernel v0.32.0
metakernel v0.27.5
Python v3.78.56 <default, Sep  4 2020, 00:03:40> [MSC v.1916 32 bit <intel>]
Python path: C:\Users\myuser\anaconda3\python.exe

Conecting to Octave...
PS C:\Users\myuser> Can't load 'C:\Users\myuser\anaconda3\lib\site-packages\metakernel\magics\shell_magic.py' : error <pexpect.popen_spawn.PopenSpawn object at 0x033C3178>
searcher: searcher_re:
    0: re.compiler<'>'>
<pexpect.popen_spawn.PopenSpawn object at 0x033C3178>
searcher: searcher_re:
    0: re.compiler<'>'>
Octave conection established
Octave kernel v0.32.0 running GNU Octave v6.1.0
Graphics toolkit: fltk
available toolkits: [1,1] = fltk
    [1,2] = gnuplot
>

when trying to plot in the jupyter notebook the console keeps sending a similar error

PS C:\Users\myuser> [MetaKernelApp] ERROR : Can't load 'C:\Users\myuser\anaconda3\lib\site-packages\metakernel\magics\shell_magic.py' : error <pexpect.popen_spawn.PopenSpawn object at 0x0341C718>
searcher: searcher_re:
    0: re.compiler<'>'>
<pexpect.popen_spawn.PopenSpawn object at 0x0341C718>
searcher: searcher_re:
    0: re.compiler<'>'>

That seems to be also affiliated with accessing the magic.py file in the metakernel package, when plotting.

@larssp
Copy link

larssp commented Mar 12, 2021

Adding set(gcf,'Visible','on') at the end of the plotting cell is a quick fix, but in octave 5.2.0 'Visible' is also 'off' and inline plotting works.

@lukkesweet
Copy link

I saw this answer over on StackOverflow but you can add the command

graphics_toolkit("gnuplot")

to the beginning of your script to make it work. Does anyone know how to add this to the kernel?

@dsblank
Copy link
Member

dsblank commented Mar 12, 2021

Looks like that is set in the config settings "backend":

https:/Calysto/octave_kernel/blob/master/octave_kernel/kernel.py#L215

https:/Calysto/octave_kernel#configuration

So:

$ cat ~/.jupyter/octave_kernel_config.py
c.OctaveKernel.plot_settings = dict(backend='gnuplot')

@larssp
Copy link

larssp commented Mar 15, 2021

Quite peculiar, graphics_toolkit() returns gnuplot from the start but octave uses fltk for plotting instead.
Unless one additionally invokes graphics_toolkit('gnuplot').

See following comparison (Jupyter Lab, WinPython, Win10):

octave 6.2.0
version()
ans = 6.2.0
graphics_toolkit()
ans = gnuplot
loaded_graphics_toolkits()
ans =
{
  [1,1] = gnuplot
}
plot(1:10)
Inline plot failed, consider trying another graphics toolkit
error: print: figure must be visible or qt toolkit must be used with __gl_window__ property 'on' or QT_OFFSCREEN feature available
error: called from
    _make_figures>safe_print at line 125 column 7
    _make_figures at line 49 column 13
fig = figure()
h = plot(1:10);
xlabel('\varphi') % additional indicator: \varphi is not suported in fltk, but it is in gnuplot
set(fig,'Visible','on')
toolkit = get(fig,"__graphics_toolkit__")
fig = 1
toolkit = fltk

(plot is shown, xlabel reads verbatim \varphi )

graphics_toolkit("gnuplot")
loaded_graphics_toolkits()
ans =
{
  [1,1] = fltk
  [1,2] = gnuplot
}
fig2 = figure()
h = plot(1:10);
xlabel('\varphi')
toolkit = get(fig2,"__graphics_toolkit__")
fig2 = 1
toolkit = gnuplot

(plot is shown, xlabel shows correct symbol)

octave 5.2.0
version()
ans = 5.2.0
graphics_toolkit()
ans = gnuplot
loaded_graphics_toolkits()
ans =
{
  [1,1] = gnuplot
}
fig2 = figure()
h = plot(1:10);
xlabel('\varphi')
get(fig2,"__graphics_toolkit__")
fig2 =  1
ans = gnuplot

(plot is shown, xlabel shows correct symbol)

graphics_toolkit("fltk")
loaded_graphics_toolkits()
ans =
{
  [1,1] = fltk
  [1,2] = gnuplot
}
fig = figure()
h = plot(1:10);
xlabel('\varphi') % additional indicator: \varphi is not suported in fltk, but it is in gnuplot
set(fig,'Visible','on')
toolkit = get(fig,"__graphics_toolkit__")
fig =  1
toolkit = fltk

(plot is shown, xlabel reads verbatim \varphi )

fig = figure()
h = plot(1:10);
xlabel('\varphi') % additional indicator: \varphi is not suported in fltk, but it is in gnuplot
% setting 'Visible' to 'on' omitted
toolkit = get(fig,"__graphics_toolkit__")
fig =  1
toolkit = fltk


Inline plot failed, consider trying another graphics toolkit
error: print: figure must be visible or qt toolkit must be used with __gl_window__ property 'on' or QT_OFFSCREEN feature available
error: called from
    _make_figures>safe_print at line 125 column 7
    _make_figures at line 49 column 13

Even though octave bug report 60095 looks kind of related, this is not reproducible with octave-cli.exe (v6.2.0) nor octave-gui.exe.

@foxserie
Copy link
Author

foxserie commented Nov 2, 2021

Okey I now moved on to Octave 6.3.0 but the problem persists, a solution is as @lukkesweet has mentioned putting on every script

graphics_toolkit("gnuplot")

I wanted to evade doing this all the time by putting

c.OctaveKernel.plot_settings = dict(backend='gnuplot')

in a octave_kernel_config.py located at /.jupyer

as @dsblank suggested but then the notebook doesn't print anything despite not sending any errors.

Octave 4.4.1 didn't have this plotting related problems, someone knows if notebooks made with the kernel pointing to 4.4.1 would later be usable if oppened but with the kernel pointing to another version of Octave?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants