Ask Your Question
2

plot sage Graphics() from jupyter notebok in CoCalc

asked 2017-09-08 14:24:35 +0200

ADuC812 gravatar image

updated 2017-09-08 14:27:44 +0200

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 flag offensive close merge delete

Comments

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

kcrisman gravatar imagekcrisman ( 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.

slelievre gravatar imageslelievre ( 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)

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

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-09-12 17:59:02 +0200

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
var('x')
p=plot(sin(x),(x,-2*pi,2*pi))
p.save('tmp.png')
Image("tmp.png")
edit flag offensive delete link more

Comments

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
main_plot = figu.add_axes((0.2,0.2,0.7,0.7))
Gr.matplotlib('a.svg', figure=figu, sub=main_plot)
figu.show()
ADuC812 gravatar imageADuC812 ( 2017-09-14 10:24:09 +0200 )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

Stats

Asked: 2017-09-08 14:24:35 +0200

Seen: 1,630 times

Last updated: Sep 12 '17