Ask Your Question

plot sage Graphics() from jupyter notebok in CoCalc

asked 2017-09-08 07:24:35 -0500

ADuC812 gravatar image

updated 2017-09-08 07:27:44 -0500

I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:

from sage.all import *

This code outputs "Graphics object consisting of 1 graphics primitive".

Pyplot plotting works fine. There are a number of old posts with the similar problem ( ex., some of them recommend changing matplotlib backend with %matplotlib inline which does not help. Is there a way to output sage Graphics() inline without using pyplot?

edit retag flag offensive close merge delete


To potential answerers: It seems like this might not be specific to CoCalc, but just in general Jupyter.

kcrisman gravatar imagekcrisman ( 2017-09-08 11:36:29 -0500 )edit

In your Jupyter worksheet, are you using the Sage kernel or the Python kernel?

You can select the "Kernel" menu and change kernel to use the SageMath kernel. This might solve your plotting issue. If not, can you make the worksheet public and link to it? This might help understand the problem.

slelievre gravatar imageslelievre ( 2017-09-08 22:53:42 -0500 )edit

My idea is to use Python kernel but import sage as a library (actually, only specific features, incl. plotting)

ADuC812 gravatar imageADuC812 ( 2017-09-10 11:44:42 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-09-12 10:59:02 -0500

calc314 gravatar image

Here is something that works, although I don't view it as perfect.

from sage.all import *
from IPython.display import Image
edit flag offensive delete link more


Just for completeness - I include here pyplot solution which is also not perfect but at least does not require temporary files

import matplotlib.pyplot as plt
from sage.all import *
figu = plt.figure() # you may set the size here
main_plot = figu.add_axes((0.2,0.2,0.7,0.7))
Gr.matplotlib('a.svg', figure=figu, sub=main_plot)
ADuC812 gravatar imageADuC812 ( 2017-09-14 03:24:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-09-08 07:24:35 -0500

Seen: 79 times

Last updated: Sep 12