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.Fri, 10 Jul 2015 13:57:45 +0200Plotting 3D points in a certain wayhttps://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/ I wish to recreate this sort of plot: http://i.imgur.com/19UPf5D.png i.e, plot 3d points in the xyz plane and connect the points by a line.
Does anyone know how to do that?
I found: http://doc.sagemath.org/html/en/reference/plotting/sage/plot/line.html but I haven't been able to find exactly what I want.Wed, 08 Jul 2015 20:15:31 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/Answer by fidbc for <p>I wish to recreate this sort of plot: <a href="http://i.imgur.com/19UPf5D.png">http://i.imgur.com/19UPf5D.png</a> i.e, plot 3d points in the xyz plane and connect the points by a line.</p>
<p>Does anyone know how to do that?</p>
<p>I found: <a href="http://doc.sagemath.org/html/en/reference/plotting/sage/plot/line.html">http://doc.sagemath.org/html/en/refer...</a> but I haven't been able to find exactly what I want.</p>
https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?answer=27284#post-id-27284Maybe you can try something of the form
# list of points
pts = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 2, 2), (3, 3, 2), (3, 3, 3), (4, 3, 3), (4, 4, 3), (4, 4, 4), (5, 4, 4), (5, 5, 4), (5, 5, 5), (6, 5, 5), (6, 6, 5), (6, 6, 6), (7, 6, 6), (7, 7, 6)]
# some red segments
red_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==0]
# some green segments
green_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==1]
# some blue segments
blue_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==2]
# empty graphics object
P=Graphics()
for rs in red_segments:
P += line3d(rs,color='red')
for gs in green_segments:
P += line3d(gs,color='green')
for bs in blue_segments:
P += line3d(bs,color='blue')
P+=point3d(pts,color='black')
P
Sample output:
![image description](/upfiles/14363824898209332.png)
Update: Removed bug on 2nd line of code and added a last line (curiously `P.show()` does not actually show the plot in cloud.sagemath.com).Wed, 08 Jul 2015 20:45:19 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?answer=27284#post-id-27284Comment by Nomly for <p>Maybe you can try something of the form</p>
<pre><code># list of points
pts = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 2, 2), (3, 3, 2), (3, 3, 3), (4, 3, 3), (4, 4, 3), (4, 4, 4), (5, 4, 4), (5, 5, 4), (5, 5, 5), (6, 5, 5), (6, 6, 5), (6, 6, 6), (7, 6, 6), (7, 7, 6)]
# some red segments
red_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==0]
# some green segments
green_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==1]
# some blue segments
blue_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==2]
# empty graphics object
P=Graphics()
for rs in red_segments:
P += line3d(rs,color='red')
for gs in green_segments:
P += line3d(gs,color='green')
for bs in blue_segments:
P += line3d(bs,color='blue')
P+=point3d(pts,color='black')
P
</code></pre>
<p>Sample output:
<img alt="image description" src="/upfiles/14363824898209332.png"/></p>
<p>Update: Removed bug on 2nd line of code and added a last line (curiously <code>P.show()</code>does not actually show the plot in <a href="http://cloud.sagemath.com">cloud.sagemath.com</a>).</p>
https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27287#post-id-27287Hi fidbc, I attempted to run your code, but encountered errors. In what environment did you run this in? [Error](http://i.imgur.com/Oprm2rH.png) (This is Ozera, but the Ozera account wouldn't let me post a comment)Thu, 09 Jul 2015 00:25:04 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27287#post-id-27287Comment by Nomly for <p>Maybe you can try something of the form</p>
<pre><code># list of points
pts = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 2, 2), (3, 3, 2), (3, 3, 3), (4, 3, 3), (4, 4, 3), (4, 4, 4), (5, 4, 4), (5, 5, 4), (5, 5, 5), (6, 5, 5), (6, 6, 5), (6, 6, 6), (7, 6, 6), (7, 7, 6)]
# some red segments
red_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==0]
# some green segments
green_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==1]
# some blue segments
blue_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==2]
# empty graphics object
P=Graphics()
for rs in red_segments:
P += line3d(rs,color='red')
for gs in green_segments:
P += line3d(gs,color='green')
for bs in blue_segments:
P += line3d(bs,color='blue')
P+=point3d(pts,color='black')
P
</code></pre>
<p>Sample output:
<img alt="image description" src="/upfiles/14363824898209332.png"/></p>
<p>Update: Removed bug on 2nd line of code and added a last line (curiously <code>P.show()</code>does not actually show the plot in <a href="http://cloud.sagemath.com">cloud.sagemath.com</a>).</p>
https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27292#post-id-27292@fidbc How odd. Do you know why replacing it with simply 'P' is the solution. In the documentation I read, it was always using the show() function. Also, is there a way to remove the bounding box? I'm not sure where the frame=False argument would go.Thu, 09 Jul 2015 06:39:59 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27292#post-id-27292Comment by fidbc for <p>Maybe you can try something of the form</p>
<pre><code># list of points
pts = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 2, 2), (3, 3, 2), (3, 3, 3), (4, 3, 3), (4, 4, 3), (4, 4, 4), (5, 4, 4), (5, 5, 4), (5, 5, 5), (6, 5, 5), (6, 6, 5), (6, 6, 6), (7, 6, 6), (7, 7, 6)]
# some red segments
red_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==0]
# some green segments
green_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==1]
# some blue segments
blue_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==2]
# empty graphics object
P=Graphics()
for rs in red_segments:
P += line3d(rs,color='red')
for gs in green_segments:
P += line3d(gs,color='green')
for bs in blue_segments:
P += line3d(bs,color='blue')
P+=point3d(pts,color='black')
P
</code></pre>
<p>Sample output:
<img alt="image description" src="/upfiles/14363824898209332.png"/></p>
<p>Update: Removed bug on 2nd line of code and added a last line (curiously <code>P.show()</code>does not actually show the plot in <a href="http://cloud.sagemath.com">cloud.sagemath.com</a>).</p>
https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27290#post-id-27290Sorry @Ozera, @Nomly. My code had a bug but I think it works now. I'm running this code in cloud.sagemath.comThu, 09 Jul 2015 05:52:51 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27290#post-id-27290Comment by fidbc for <p>Maybe you can try something of the form</p>
<pre><code># list of points
pts = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 2, 2), (3, 3, 2), (3, 3, 3), (4, 3, 3), (4, 4, 3), (4, 4, 4), (5, 4, 4), (5, 5, 4), (5, 5, 5), (6, 5, 5), (6, 6, 5), (6, 6, 6), (7, 6, 6), (7, 7, 6)]
# some red segments
red_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==0]
# some green segments
green_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==1]
# some blue segments
blue_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==2]
# empty graphics object
P=Graphics()
for rs in red_segments:
P += line3d(rs,color='red')
for gs in green_segments:
P += line3d(gs,color='green')
for bs in blue_segments:
P += line3d(bs,color='blue')
P+=point3d(pts,color='black')
P
</code></pre>
<p>Sample output:
<img alt="image description" src="/upfiles/14363824898209332.png"/></p>
<p>Update: Removed bug on 2nd line of code and added a last line (curiously <code>P.show()</code>does not actually show the plot in <a href="http://cloud.sagemath.com">cloud.sagemath.com</a>).</p>
https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27298#post-id-27298@Nomly It seems that `show(P,frame=False)` works fine. Maybe this is a bug, I'll ask in the sage-support group.Thu, 09 Jul 2015 19:25:16 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27298#post-id-27298Comment by fidbc for <p>Maybe you can try something of the form</p>
<pre><code># list of points
pts = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 2, 2), (3, 3, 2), (3, 3, 3), (4, 3, 3), (4, 4, 3), (4, 4, 4), (5, 4, 4), (5, 5, 4), (5, 5, 5), (6, 5, 5), (6, 6, 5), (6, 6, 6), (7, 6, 6), (7, 7, 6)]
# some red segments
red_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==0]
# some green segments
green_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==1]
# some blue segments
blue_segments = [[pts[i],pts[i+1]] for i in range(len(pts)-1) if i%3==2]
# empty graphics object
P=Graphics()
for rs in red_segments:
P += line3d(rs,color='red')
for gs in green_segments:
P += line3d(gs,color='green')
for bs in blue_segments:
P += line3d(bs,color='blue')
P+=point3d(pts,color='black')
P
</code></pre>
<p>Sample output:
<img alt="image description" src="/upfiles/14363824898209332.png"/></p>
<p>Update: Removed bug on 2nd line of code and added a last line (curiously <code>P.show()</code>does not actually show the plot in <a href="http://cloud.sagemath.com">cloud.sagemath.com</a>).</p>
https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27304#post-id-27304@Nomly: This is a known bug: https://github.com/sagemathinc/smc/issues/15Fri, 10 Jul 2015 13:57:45 +0200https://ask.sagemath.org/question/27281/plotting-3d-points-in-a-certain-way/?comment=27304#post-id-27304