ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 26 Oct 2011 11:42:38 -0500Mathematica graphics in a sage notebook - second takehttp://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/[This](http://ask.sagemath.org/question/765/mathematica-graphics-in-a-sage-notebook) question was already asked, but the answer doesn't work for me so I was suggested that I ask it again with the specifics of my problem. So here goes. <br>
To quote [Simons's](http://ask.sagemath.org/users/58/simon/) answer:<br>
In [SAGE_ROOT/devel/sage/sage/interfaces/mathematica.py](http://hg.sagemath.org/sage-main/file/2a2abbcad325/sage/interfaces/mathematica.py#l824) you find the show() function:<br>
def show(self, filename=None, ImageSize=600):
r"""
Show a mathematica expression or plot in the Sage notebook.
EXAMPLES::
sage: P = mathematica('Plot[Sin[x],{x,-2Pi,4Pi}]') # optional - mathematica
sage: show(P) # optional - mathematica
sage: P.show(ImageSize=800) # optional - mathematica
sage: Q = mathematica('Sin[x Cos[y]]/Sqrt[1-x^2]') # optional - mathematica
sage: show(Q) # optional - mathematica
<html><div class="math">\frac{\sin (x \cos (y))}{\sqrt{1-x^2}}</div></html>
"""
I'm not sure should I use <i>sage</i> input method or <i>mathematica</i> so I'll do both.<br>
sage input method:<br>
For test that MathKernel works:
mathematica('N[Pi,10]')
returns
3.141592654
Now if I try the first example:
P = mathematica('Plot[Sin[x],{x,-2Pi,4Pi}]')
show(P)
I get nothing, it just appears to work (waiting cursor) but no output. By checking the process list on server, MathKernel is shown.<br>
<br>
Next I tried <i>mathematica</i> input method:<br>
N[Pi,10]
returns<br>
3.141592654
Test works.
Plot[Sin[x],{x,-2Pi,4Pi}]
returns
-Graphics-
EDIT: Ubuntu Server 10.04 without GUI, Mathematica 8.0, Sage 4.7.1Sat, 22 Oct 2011 05:59:45 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/Answer by kcrisman for <p><a href="http://ask.sagemath.org/question/765/mathematica-graphics-in-a-sage-notebook">This</a> question was already asked, but the answer doesn't work for me so I was suggested that I ask it again with the specifics of my problem. So here goes. <br/>
To quote <a href="http://ask.sagemath.org/users/58/simon/">Simons's</a> answer:<br/>
In <a href="http://hg.sagemath.org/sage-main/file/2a2abbcad325/sage/interfaces/mathematica.py#l824">SAGE_ROOT/devel/sage/sage/interfaces/mathematica.py</a> you find the show() function:<br/></p>
<pre><code>def show(self, filename=None, ImageSize=600):
r"""
Show a mathematica expression or plot in the Sage notebook.
EXAMPLES::
sage: P = mathematica('Plot[Sin[x],{x,-2Pi,4Pi}]') # optional - mathematica
sage: show(P) # optional - mathematica
sage: P.show(ImageSize=800) # optional - mathematica
sage: Q = mathematica('Sin[x Cos[y]]/Sqrt[1-x^2]') # optional - mathematica
sage: show(Q) # optional - mathematica
<html><div class="math">\frac{\sin (x \cos (y))}{\sqrt{1-x^2}}</div></html>
"""
</code></pre>
<p>I'm not sure should I use <i>sage</i> input method or <i>mathematica</i> so I'll do both.<br/>
sage input method:<br/>
For test that MathKernel works:</p>
<pre><code>mathematica('N[Pi,10]')
</code></pre>
<p>returns</p>
<pre><code>3.141592654
</code></pre>
<p>Now if I try the first example:</p>
<pre><code>P = mathematica('Plot[Sin[x],{x,-2Pi,4Pi}]')
show(P)
</code></pre>
<p>I get nothing, it just appears to work (waiting cursor) but no output. By checking the process list on server, MathKernel is shown.<br/>
<br/>
Next I tried <i>mathematica</i> input method:<br/></p>
<pre><code>N[Pi,10]
</code></pre>
<p>returns<br/></p>
<pre><code>3.141592654
</code></pre>
<p>Test works.</p>
<pre><code>Plot[Sin[x],{x,-2Pi,4Pi}]
</code></pre>
<p>returns</p>
<pre><code>-Graphics-
</code></pre>
<p>EDIT: Ubuntu Server 10.04 without GUI, Mathematica 8.0, Sage 4.7.1</p>
http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?answer=12799#post-id-12799I don't know if this is the answer. But notice in the documentation:
Show a mathematica expression or plot in the Sage notebook.
The code has
P.chdir(os.path.abspath("."))
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
P.eval(s)
P.chdir(orig_dir)
So it's doing the `chdir` thing inside the notebook in order to make sure the graphics file is found in the right place there, but that won't work with the command line.
You may, though, be able to evaluate a Mma command that just saves the file to some `filename`. It looks like that `Export` command might do it, but I don't have Mma, so I couldn't tell. I bet it's worth a shot, though.Sat, 22 Oct 2011 15:44:29 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?answer=12799#post-id-12799Comment by kcrisman for <p>I don't know if this is the answer. But notice in the documentation:</p>
<pre><code>Show a mathematica expression or plot in the Sage notebook.
</code></pre>
<p>The code has</p>
<pre><code> P.chdir(os.path.abspath("."))
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
P.eval(s)
P.chdir(orig_dir)
</code></pre>
<p>So it's doing the <code>chdir</code> thing inside the notebook in order to make sure the graphics file is found in the right place there, but that won't work with the command line. </p>
<p>You may, though, be able to evaluate a Mma command that just saves the file to some <code>filename</code>. It looks like that <code>Export</code> command might do it, but I don't have Mma, so I couldn't tell. I bet it's worth a shot, though.</p>
http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21034#post-id-21034And you're saying that this doesn't work in the notebook? I thought you were using command line... maybe there is something weird. Is Mathematica in your path?Tue, 25 Oct 2011 05:18:27 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21034#post-id-21034Comment by enedene for <p>I don't know if this is the answer. But notice in the documentation:</p>
<pre><code>Show a mathematica expression or plot in the Sage notebook.
</code></pre>
<p>The code has</p>
<pre><code> P.chdir(os.path.abspath("."))
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
P.eval(s)
P.chdir(orig_dir)
</code></pre>
<p>So it's doing the <code>chdir</code> thing inside the notebook in order to make sure the graphics file is found in the right place there, but that won't work with the command line. </p>
<p>You may, though, be able to evaluate a Mma command that just saves the file to some <code>filename</code>. It looks like that <code>Export</code> command might do it, but I don't have Mma, so I couldn't tell. I bet it's worth a shot, though.</p>
http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21035#post-id-21035I would really like to have the output in web interface, otherwise it's more practical to connect to mathematica via shell.Tue, 25 Oct 2011 05:16:55 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21035#post-id-21035Comment by enedene for <p>I don't know if this is the answer. But notice in the documentation:</p>
<pre><code>Show a mathematica expression or plot in the Sage notebook.
</code></pre>
<p>The code has</p>
<pre><code> P.chdir(os.path.abspath("."))
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
P.eval(s)
P.chdir(orig_dir)
</code></pre>
<p>So it's doing the <code>chdir</code> thing inside the notebook in order to make sure the graphics file is found in the right place there, but that won't work with the command line. </p>
<p>You may, though, be able to evaluate a Mma command that just saves the file to some <code>filename</code>. It looks like that <code>Export</code> command might do it, but I don't have Mma, so I couldn't tell. I bet it's worth a shot, though.</p>
http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21031#post-id-21031@kcrisman exactly I'm using web interface notebook, and there I can't get a graphical output. Since sage can find Mathematica to calculate N[Pi,10], it should do so for graphics. And the process can be seen if I connect to server via ssh and run top command.Tue, 25 Oct 2011 11:45:21 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21031#post-id-21031Comment by kcrisman for <p>I don't know if this is the answer. But notice in the documentation:</p>
<pre><code>Show a mathematica expression or plot in the Sage notebook.
</code></pre>
<p>The code has</p>
<pre><code> P.chdir(os.path.abspath("."))
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
P.eval(s)
P.chdir(orig_dir)
</code></pre>
<p>So it's doing the <code>chdir</code> thing inside the notebook in order to make sure the graphics file is found in the right place there, but that won't work with the command line. </p>
<p>You may, though, be able to evaluate a Mma command that just saves the file to some <code>filename</code>. It looks like that <code>Export</code> command might do it, but I don't have Mma, so I couldn't tell. I bet it's worth a shot, though.</p>
http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21030#post-id-21030Huh. I'm stumped, but I'm not an expert on this either. If you don't get any more answers here, I'd try sage-support@googlegroups.com, where there are definitely people who use the Mma interface regularly. Sorry I cannot help more.Wed, 26 Oct 2011 02:36:04 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21030#post-id-21030Comment by enedene for <p>I don't know if this is the answer. But notice in the documentation:</p>
<pre><code>Show a mathematica expression or plot in the Sage notebook.
</code></pre>
<p>The code has</p>
<pre><code> P.chdir(os.path.abspath("."))
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
P.eval(s)
P.chdir(orig_dir)
</code></pre>
<p>So it's doing the <code>chdir</code> thing inside the notebook in order to make sure the graphics file is found in the right place there, but that won't work with the command line. </p>
<p>You may, though, be able to evaluate a Mma command that just saves the file to some <code>filename</code>. It looks like that <code>Export</code> command might do it, but I don't have Mma, so I couldn't tell. I bet it's worth a shot, though.</p>
http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21027#post-id-21027@kcirsman no problem, you tried to help, I respect that.Wed, 26 Oct 2011 11:42:38 -0500http://ask.sagemath.org/question/8405/mathematica-graphics-in-a-sage-notebook-second-take/?comment=21027#post-id-21027