ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 14 Sep 2017 10:24:09 +0200plot sage Graphics() from jupyter notebok in CoCalchttps://ask.sagemath.org/question/38759/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/10988/in-line-graphics-for-sage-in-ipython-notebook/), 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?Fri, 08 Sep 2017 14:24:35 +0200https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/Comment by kcrisman for <p>I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:</p>
<pre><code>from sage.all import *
var('x')
plot(sin(x)).show()
</code></pre>
<p>This code outputs "Graphics object consisting of 1 graphics primitive". </p>
<p>Pyplot plotting works fine.
There are a number of old posts with the similar problem ( ex. <a href="https://ask.sagemath.org/question/10988/in-line-graphics-for-sage-in-ipython-notebook/">https://ask.sagemath.org/question/109...</a>), 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?</p>
https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38762#post-id-38762To potential answerers: It seems like this might not be specific to CoCalc, but just in general Jupyter.Fri, 08 Sep 2017 18:36:29 +0200https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38762#post-id-38762Comment by ADuC812 for <p>I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:</p>
<pre><code>from sage.all import *
var('x')
plot(sin(x)).show()
</code></pre>
<p>This code outputs "Graphics object consisting of 1 graphics primitive". </p>
<p>Pyplot plotting works fine.
There are a number of old posts with the similar problem ( ex. <a href="https://ask.sagemath.org/question/10988/in-line-graphics-for-sage-in-ipython-notebook/">https://ask.sagemath.org/question/109...</a>), 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?</p>
https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38784#post-id-38784My idea is to use Python kernel but import sage as a library (actually, only specific features, incl. plotting)Sun, 10 Sep 2017 18:44:42 +0200https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38784#post-id-38784Comment by slelievre for <p>I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:</p>
<pre><code>from sage.all import *
var('x')
plot(sin(x)).show()
</code></pre>
<p>This code outputs "Graphics object consisting of 1 graphics primitive". </p>
<p>Pyplot plotting works fine.
There are a number of old posts with the similar problem ( ex. <a href="https://ask.sagemath.org/question/10988/in-line-graphics-for-sage-in-ipython-notebook/">https://ask.sagemath.org/question/109...</a>), 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?</p>
https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38767#post-id-38767In 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.Sat, 09 Sep 2017 05:53:42 +0200https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38767#post-id-38767Answer by calc314 for <p>I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:</p>
<pre><code>from sage.all import *
var('x')
plot(sin(x)).show()
</code></pre>
<p>This code outputs "Graphics object consisting of 1 graphics primitive". </p>
<p>Pyplot plotting works fine.
There are a number of old posts with the similar problem ( ex. <a href="https://ask.sagemath.org/question/10988/in-line-graphics-for-sage-in-ipython-notebook/">https://ask.sagemath.org/question/109...</a>), 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?</p>
https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?answer=38804#post-id-38804Here 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")Tue, 12 Sep 2017 17:59:02 +0200https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?answer=38804#post-id-38804Comment by ADuC812 for <p>Here is something that works, although I don't view it as perfect.</p>
<pre><code>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")
</code></pre>
https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38813#post-id-38813Just 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()Thu, 14 Sep 2017 10:24:09 +0200https://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/?comment=38813#post-id-38813