plot3d doesn't work in jupyterlab / jupyter notebook

499 views
Skip to first unread message

Kolen Cheung

unread,
Nov 17, 2018, 6:34:20 PM11/17/18
to sage-support
Hi,

I'm running SageMath 8.4 kernel in jupyterlab and also jupyter notebook. But running `plot3d(x * y, (x, -1, 1), (y, -1, 1))` gives me a blank space. Is there a command I first need to run before it shows? I tried `%matplotlib inline` but it doesn't help.

`plot` works though.

Thanks!

Dima Pasechnik

unread,
Nov 17, 2018, 7:01:01 PM11/17/18
to sage-s...@googlegroups.com
On Sat, Nov 17, 2018 at 11:34 PM Kolen Cheung <christi...@gmail.com> wrote:
>
> Hi,
>
> I'm running SageMath 8.4 kernel in jupyterlab and also jupyter notebook. But running `plot3d(x * y, (x, -1, 1), (y, -1, 1))` gives me a blank space. Is there a command I first need to run before it shows? I tried `%matplotlib inline` but it doesn't help.

Have a look at http://doc.sagemath.org/html/en/reference/plot3d/threejs.html

there are several plotting 3d backends available in Sage, you may try
finding one that works in your
setting.http://doc.sagemath.org/html/en/reference/plot3d/index.html#backends


> `plot` works though.
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.

Kolen Cheung

unread,
Nov 17, 2018, 8:32:34 PM11/17/18
to sage-support

I tried both

plot3d(sin(pi * sqrt(x**2 + y**2)) / sqrt(x**2 + y**2), (x, -5, 5), (y, -5, 5), viewer='threejs')
...
p1 = sphere(color='red', opacity='.5')
p2 = sphere((-1,-1,1), color='cyan', opacity='.3')
p3 = sphere((1,-1,-1), color='yellow', opacity='.7')
show(p1 + p2 + p3, viewer='threejs')

Again on both jupyter notebook and jupyterlab, on both Safari and Chrome. Are you sure there isn’t other dependencies?

I checked the HTML console and found this:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (preact.min.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (index.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (preact-compat.min.js.map, line 0)

Are there any jupyter widgets that I should install?

John H Palmieri

unread,
Nov 17, 2018, 10:21:02 PM11/17/18
to sage-support
This is on OS X? How did you install Sage? (It works for me with Sage built from scratch on both OS X 10.13.6 and OS X 10.14.1.)

  John

Kolen Cheung

unread,
Nov 17, 2018, 10:24:58 PM11/17/18
to sage-support
I couldn't install sage on macOS Mojave, I'm guessing it isn't compatible with Mojave yet.

Currently it's like this: on an ArchLinux machine, install sage through pacman, and install the sagemath kernel to my jupyterlab hub. And then through the jupyterlab-hub I remote it and use the sagemath kernel and typed the above commands.

I'm guessing it requires some widgets to be installed in jupyter for them to work. Since I'm not using the Sage notebook interface but a Jupyterlab-hub instance that has the sagemath kernel installed.

John H Palmieri

unread,
Nov 18, 2018, 1:34:22 AM11/18/18
to sage-support


On Saturday, November 17, 2018 at 7:24:58 PM UTC-8, Kolen Cheung wrote:
I couldn't install sage on macOS Mojave, I'm guessing it isn't compatible with Mojave yet.

My message said that I had installed it on OS X 10.14.1, which is Mojave. You need to have Xcode installed with the command line tools, or at least the command line tools. Try searching the google group sage-devel for information about installing with Mojave.

Kolen Cheung

unread,
Nov 18, 2018, 2:07:58 AM11/18/18
to sage-support
I have the command line tool. I use `brew cask install sage` and it finishes download without proceeding. It is possible the formula in caskroom need to be updated though.

But the problem is that I can't get it work even on the Linux installation where everything else' fine so far, except plot3d.

Regards,
Kolen
--

Dima Pasechnik

unread,
Nov 18, 2018, 4:26:48 AM11/18/18
to sage-s...@googlegroups.com
How about Sage in terminal, does 3d plotting work there?

Kolen Cheung

unread,
Nov 18, 2018, 5:25:43 PM11/18/18
to sage-support
sage: y = var('y')
sage: plot3d(x * y, (x, -1, 1), (y, -1, 1), viewer='threejs')
Launched html viewer for Graphics3d Object

I didn’t see anything since I’m remote ssh. I tried both ssh -X and ssh -Y but they doesn’t work.

I don’t have a local machine that has a working sage yet. So can’t test that.

Thanks.

Nils Bruin

unread,
Nov 18, 2018, 6:49:30 PM11/18/18
to sage-support
It depends a little bit on how you install the sage kernel into your jupyter notebook server, but chances are you have to do some extra work to install some notebook extensions.

In the sage install, in "<SAGE_ROOT>/local/share" there are 3 subdirs "jsmol, "mathjax", "threejs". These need to be findable as "nbextensions" by your jupyter. Having them symlinked in, say, /usr/local/share/jupyter/nbextensions should do the trick [if your sage kernel lives in .../kernels/sagemath , you would probably want to symlink these extensions from .../nbextensions ]

Kolen Cheung

unread,
Nov 18, 2018, 9:38:49 PM11/18/18
to sage-support

I tried to install threejs by jupyter labextension install jupyter-threejs but it still doesn’t work. I tried on both jupyter and jupyterlab. I didn’t tried symlinking the directories you mentioned though, because I don’t want to mess up the virtual environments created by conda (my jupyterlab environment is created using conda.)

Enrique Artal

unread,
Nov 18, 2018, 11:45:47 PM11/18/18
to sage-support
If I am not wrong it works from a terminal and also if one uses either sage -m jupyter or sage -n jupyterlab.
It is possible to use it directly from jupyter or jupyter lab if the sagemath kernel is availabe to jupyter, e.g. at /usr/local/share/jupyter/kernels or .local/share/jupyter/kernels, and the nbextensions (jsmol,mathjax threejs) linked should not interfere your jupyter installation..
It may be more complicated using jupyterhub; at least for threejs, if I am not wrong something must be changed in order to look for the non-found files in external places since jupyterhub is not able to find them locally. At some point I was able to use it changing some sage files but I do not know how to do it properly.

Enrique Artal

unread,
Nov 18, 2018, 11:46:32 PM11/18/18
to sage-support
If I am not wrong it works from a terminal and also if one uses either sage -m jupyter or sage -n jupyterlab.
It is possible to use it directly from jupyter or jupyter lab if the sagemath kernel is availabe to jupyter, e.g. at /usr/local/share/jupyter/kernels or .local/share/jupyter/kernels, and the nbextensions (jsmol,mathjax threejs) linked should not interfere your jupyter installation..
It may be more complicated using jupyterhub; at least for threejs, if I am not wrong something must be changed in order to look for the non-found files in external places since jupyterhub is not able to find them locally. At some point I was able to use it changing some sage files but I do not know how to do it properly.

El lunes, 19 de noviembre de 2018, 3:38:49 (UTC+1), Kolen Cheung escribió:

Antonio Rojas

unread,
Nov 18, 2018, 11:50:09 PM11/18/18
to sage-support

El domingo, 18 de noviembre de 2018, 4:24:58 (UTC+1), Kolen Cheung escribió:
Currently it's like this: on an ArchLinux machine, install sage through pacman, and install the sagemath kernel to my jupyterlab hub. And then through the jupyterlab-hub I remote it and use the sagemath kernel and typed the above commands.

I'm guessing it requires some widgets to be installed in jupyter for them to work. Since I'm not using the Sage notebook interface but a Jupyterlab-hub instance that has the sagemath kernel installed.


The three.js version shipped by Arch is too new and not supported by Sage. Either use jsmol (which is still the default), or use the online version of three.js (viewer='threejs', online=True) (with sagemath 8.4-4, in previous versions the online version doesn't work either)

slelievre

unread,
Nov 19, 2018, 4:48:33 AM11/19/18
to sage-support
Mon 2018-11-19 05:50:09 UTC+1, Antonio Rojas:

>
> The three.js version shipped by Arch is too new and not
> supported by Sage. Either use jsmol (which is still the default),
> or use the online version of three.js (viewer='threejs', online=True)
> (with sagemath 8.4-4, in previous versions the online version
> doesn't work either)

See Sage Trac ticket 26718 for upgrading to the latest version of three.js:

Kolen Cheung

unread,
Nov 19, 2018, 7:02:23 AM11/19/18
to sage-support

Thanks all for the comments. In the end I choose this temporary fix plot3d(sin(pi * sqrt(x**2 + y**2)) / sqrt(x**2 + y**2), (x, -5, 5), (y, -5, 5), viewer='threejs', online=True). I prefer to stick to jupyterlab hub and using conda to manage it so I didn’t try symlink those from sage in the jupyterlab environment.

Regarding the three.js shipped by Arch, may be it didn’t work. But it isn’t the original of the problem I’m experiencing since in the browser’s console it clearly indicates the three.js cannot be found. I tried to install three.js the “jupyter way”, i.e. jupyter labextension install jupyter-threejs, but it didn’t work for both jupyterlab and jupyter notebook.

Reply all
Reply to author
Forward
0 new messages