# plot sage Graphics() from jupyter notebok in CoCalc

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 *
var('x')
plot(sin(x)).show()


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. https://ask.sagemath.org/question/109...), 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 close merge delete

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

( 2017-09-08 18:36:29 +0200 )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.

( 2017-09-09 05:53:42 +0200 )edit

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

( 2017-09-10 18:44:42 +0200 )edit

Sort by ยป oldest newest most voted

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

from sage.all import *
from IPython.display import Image
var('x')
p=plot(sin(x),(x,-2*pi,2*pi))
p.save('tmp.png')
Image("tmp.png")

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 *
var('x')
Gr=plot(sin(x))
figu = plt.figure() # you may set the size here
Gr.matplotlib('a.svg', figure=figu, sub=main_plot)
figu.show()

( 2017-09-14 10:24:09 +0200 )edit