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, 17 May 2018 14:18:02 +0200Orienting and Saving 3D Plotshttps://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/Hi !
I am very new to using Sage, I've started only a few weeks ago. I hope my inability to answer anyone's questions won't ruin my "karma" ! Anyway, here is my first question:
I've been experimenting with plotting 3D objects, so far. Right now, I am plotting simple cubes scattered in space. With great satisfaction, I've noticed I could initialize the point of view of my 3D plot by specifying:
orientation(0,0,0,0)
That initializes to X being horizontal, Y vertical, and Z orthogonal to the screen. Then, I specify:
G.rotate([1,0,0],pi/4).show(aspect_ratio=[1,1,1],frame=False)
and get a point of view I really like. My goal is to generate a bunch of .png files of my cubes from different points of view, and I was hoping to use this rotate() functionality with a [ for i in range(n)] type statement. Therefore, I'd really like SAGE to write a bunch of .png files without me generating images one by one and saving manually. So I tried using the save() function, like so:
G.rotate([1,0,0],pi/4).save("MyImage.png",aspect_ratio=[1,1,1],frame=False)
Here is my problem: when I use the save() function, my previous orientation(0,0,0,0) statement is completely overridden, and the resulting MyImage.png I get is rotated according to rotate([1,0,0],pi/4), but not from the intented X being horizontal, Y vertical, and Z orthogonal to the screen configuration, rather, from the default point of view show() gives me, if I do not specify orientation(0,0,0,0).
Why is it so, and how can I fix this ?
Thank you very much,
Turiel.Fri, 27 Apr 2018 18:18:47 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/Comment by slelievre for <p>Hi !</p>
<p>I am very new to using Sage, I've started only a few weeks ago. I hope my inability to answer anyone's questions won't ruin my "karma" ! Anyway, here is my first question:</p>
<p>I've been experimenting with plotting 3D objects, so far. Right now, I am plotting simple cubes scattered in space. With great satisfaction, I've noticed I could initialize the point of view of my 3D plot by specifying:</p>
<p>orientation(0,0,0,0)</p>
<p>That initializes to X being horizontal, Y vertical, and Z orthogonal to the screen. Then, I specify:</p>
<p>G.rotate([1,0,0],pi/4).show(aspect_ratio=[1,1,1],frame=False)</p>
<p>and get a point of view I really like. My goal is to generate a bunch of .png files of my cubes from different points of view, and I was hoping to use this rotate() functionality with a [ for i in range(n)] type statement. Therefore, I'd really like SAGE to write a bunch of .png files without me generating images one by one and saving manually. So I tried using the save() function, like so:</p>
<p>G.rotate([1,0,0],pi/4).save("MyImage.png",aspect_ratio=[1,1,1],frame=False)</p>
<p>Here is my problem: when I use the save() function, my previous orientation(0,0,0,0) statement is completely overridden, and the resulting MyImage.png I get is rotated according to rotate([1,0,0],pi/4), but not from the intented X being horizontal, Y vertical, and Z orthogonal to the screen configuration, rather, from the default point of view show() gives me, if I do not specify orientation(0,0,0,0).</p>
<p>Why is it so, and how can I fix this ?</p>
<p>Thank you very much,
Turiel.</p>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42191#post-id-42191Welcome to Ask Sage! Thank you for your question!Fri, 27 Apr 2018 18:34:45 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42191#post-id-42191Answer by eric_g for <p>Hi !</p>
<p>I am very new to using Sage, I've started only a few weeks ago. I hope my inability to answer anyone's questions won't ruin my "karma" ! Anyway, here is my first question:</p>
<p>I've been experimenting with plotting 3D objects, so far. Right now, I am plotting simple cubes scattered in space. With great satisfaction, I've noticed I could initialize the point of view of my 3D plot by specifying:</p>
<p>orientation(0,0,0,0)</p>
<p>That initializes to X being horizontal, Y vertical, and Z orthogonal to the screen. Then, I specify:</p>
<p>G.rotate([1,0,0],pi/4).show(aspect_ratio=[1,1,1],frame=False)</p>
<p>and get a point of view I really like. My goal is to generate a bunch of .png files of my cubes from different points of view, and I was hoping to use this rotate() functionality with a [ for i in range(n)] type statement. Therefore, I'd really like SAGE to write a bunch of .png files without me generating images one by one and saving manually. So I tried using the save() function, like so:</p>
<p>G.rotate([1,0,0],pi/4).save("MyImage.png",aspect_ratio=[1,1,1],frame=False)</p>
<p>Here is my problem: when I use the save() function, my previous orientation(0,0,0,0) statement is completely overridden, and the resulting MyImage.png I get is rotated according to rotate([1,0,0],pi/4), but not from the intented X being horizontal, Y vertical, and Z orthogonal to the screen configuration, rather, from the default point of view show() gives me, if I do not specify orientation(0,0,0,0).</p>
<p>Why is it so, and how can I fix this ?</p>
<p>Thank you very much,
Turiel.</p>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?answer=42201#post-id-42201With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):
sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Sat, 28 Apr 2018 19:10:01 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?answer=42201#post-id-42201Comment by Turiel for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42203#post-id-42203I have copy pasted exactly your code, I have SageMath 8.1 as well, but I still have the same problem ! And I am using exactly your code !
I have no idea why this is happening.Sat, 28 Apr 2018 22:07:19 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42203#post-id-42203Comment by eric_g for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42205#post-id-42205Which operating system are you using? Windows?Sun, 29 Apr 2018 11:48:15 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42205#post-id-42205Comment by Turiel for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42206#post-id-42206Yes, I am using Windows 10Sun, 29 Apr 2018 13:08:06 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42206#post-id-42206Comment by eric_g for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42214#post-id-42214OK, there have been a number of issues with Jmol and Windows, which have been fixed recently (see e.g. ticket [#25025](https://trac.sagemath.org/ticket/25025). These fixes will become effective in SageMath 8.2, to be released very soon (hopefully within a few days). So I would advice to upgrade to SageMath 8.2, when it becomes available, and then try again.Sun, 29 Apr 2018 18:36:57 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42214#post-id-42214Comment by Turiel for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42216#post-id-42216Alright, I will wait patiently and let you know how it goes when SageMath 8.2 comes out.Sun, 29 Apr 2018 20:41:52 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42216#post-id-42216Comment by eric_g for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42217#post-id-42217Meanwhile, you may use [CoCalc](https://cocalc.com) to achieve what you want (indeed CoCalc is running Ubuntu Linux, which does not suffer from the above issue).Sun, 29 Apr 2018 21:50:30 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42217#post-id-42217Comment by Turiel for <p>With SageMath 8.1, the following works for me (i.e. the png figure has the same orientation as that displayed in the Jmol window):</p>
<pre><code>sage: G = cube()
sage: G.rotate([1,0,0], pi/4).show(aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
Launched jmol viewer for Graphics3d Object
sage: G.rotate([1,0,0], pi/4).save("MyImage.png", aspect_ratio=[1,1,1], orientation=(0,0,0,0), frame=False)
</code></pre>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42222#post-id-42222Thank you ! I have tried but... the following command works fine:
G.rotate([1,0,0],pi/4).show(aspect_ratio=[1,1,1],frame=False)
And this one crashes:
G.rotate([1,0,0],pi/4).show(aspect_ratio=[1,1,1],frame=False,orientation=(0,0,0,0))
And similarly this one works:
G.rotate([1,0,0],pi/4).save('ImageTest.png',aspect_ratio=[1,1,1],frame=False)
...and this one crashes:
G.rotate([1,0,0],pi/4).save('ImageTest.png',aspect_ratio=[1,1,1],frame=False,orientation(0,0,0,0))
So I still cannot get the desired point of view on my figure !Mon, 30 Apr 2018 13:03:40 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42222#post-id-42222Answer by Turiel for <p>Hi !</p>
<p>I am very new to using Sage, I've started only a few weeks ago. I hope my inability to answer anyone's questions won't ruin my "karma" ! Anyway, here is my first question:</p>
<p>I've been experimenting with plotting 3D objects, so far. Right now, I am plotting simple cubes scattered in space. With great satisfaction, I've noticed I could initialize the point of view of my 3D plot by specifying:</p>
<p>orientation(0,0,0,0)</p>
<p>That initializes to X being horizontal, Y vertical, and Z orthogonal to the screen. Then, I specify:</p>
<p>G.rotate([1,0,0],pi/4).show(aspect_ratio=[1,1,1],frame=False)</p>
<p>and get a point of view I really like. My goal is to generate a bunch of .png files of my cubes from different points of view, and I was hoping to use this rotate() functionality with a [ for i in range(n)] type statement. Therefore, I'd really like SAGE to write a bunch of .png files without me generating images one by one and saving manually. So I tried using the save() function, like so:</p>
<p>G.rotate([1,0,0],pi/4).save("MyImage.png",aspect_ratio=[1,1,1],frame=False)</p>
<p>Here is my problem: when I use the save() function, my previous orientation(0,0,0,0) statement is completely overridden, and the resulting MyImage.png I get is rotated according to rotate([1,0,0],pi/4), but not from the intented X being horizontal, Y vertical, and Z orthogonal to the screen configuration, rather, from the default point of view show() gives me, if I do not specify orientation(0,0,0,0).</p>
<p>Why is it so, and how can I fix this ?</p>
<p>Thank you very much,
Turiel.</p>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?answer=42330#post-id-42330Hi !
As eric_g suggested, this issue has been fixed for Windows 10 in SageMath 8.2 !
I ran my code exactly the same way I wrote it weeks ago, and now the .png image generated with the save function using the same arguments I used in the show function looks exactly the same as what's in the Notebook.
Thank you very much,
TurielMon, 14 May 2018 10:56:39 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?answer=42330#post-id-42330Comment by eric_g for <p>Hi !</p>
<p>As eric_g suggested, this issue has been fixed for Windows 10 in SageMath 8.2 !
I ran my code exactly the same way I wrote it weeks ago, and now the .png image generated with the save function using the same arguments I used in the show function looks exactly the same as what's in the Notebook.</p>
<p>Thank you very much,
Turiel</p>
https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42361#post-id-42361Good to hear!Thu, 17 May 2018 14:18:02 +0200https://ask.sagemath.org/question/42190/orienting-and-saving-3d-plots/?comment=42361#post-id-42361