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.Thu, 15 Nov 2018 07:47:49 -0600Plotting > 10k random 3D pointshttp://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/Hi,
First of all, I am new to SAGE, and only started using it today.
I want to plot 100 000 random 3D points in SAGE, and it takes a LOT of time just to plot 10 000 points.
This is the code I have:
def random_point(): return (random(), random(), random())
l = [random_point() for k in [1 .. 10000]]
s = point3d(l, size=5)
show(s, aspect_ratio=1)
I noticed that the last two lines take incredibly long each.
Then, after the `show`, when I try to interact with the graphic, it is blank. I can even show the boundbox and axes, but the plot is nowhere to be seen.
If I change to `[1 .. 100]`, everything works as intended, but this amount of points is not enough.
What should I do to accomplish effectively my goal?
I am using SAGE 8.1, installed on macOS via brew, after running `notebook()` on the command line and using the browser-based notebook.
Thank you!Wed, 14 Nov 2018 19:34:52 -0600http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/Comment by tmonteil for <p>Hi,</p>
<p>First of all, I am new to SAGE, and only started using it today.</p>
<p>I want to plot 100 000 random 3D points in SAGE, and it takes a LOT of time just to plot 10 000 points.</p>
<p>This is the code I have:</p>
<pre><code>def random_point(): return (random(), random(), random())
l = [random_point() for k in [1 .. 10000]]
s = point3d(l, size=5)
show(s, aspect_ratio=1)
</code></pre>
<p>I noticed that the last two lines take incredibly long each.</p>
<p>Then, after the <code>show</code>, when I try to interact with the graphic, it is blank. I can even show the boundbox and axes, but the plot is nowhere to be seen.</p>
<p>If I change to <code>[1 .. 100]</code>, everything works as intended, but this amount of points is not enough.</p>
<p>What should I do to accomplish effectively my goal?</p>
<p>I am using SAGE 8.1, installed on macOS via brew, after running <code>notebook()</code> on the command line and using the browser-based notebook.</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/?comment=44291#post-id-44291@rburing : even the construction of `s` takes time, not only the jmol plotting.Thu, 15 Nov 2018 07:47:49 -0600http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/?comment=44291#post-id-44291Comment by rburing for <p>Hi,</p>
<p>First of all, I am new to SAGE, and only started using it today.</p>
<p>I want to plot 100 000 random 3D points in SAGE, and it takes a LOT of time just to plot 10 000 points.</p>
<p>This is the code I have:</p>
<pre><code>def random_point(): return (random(), random(), random())
l = [random_point() for k in [1 .. 10000]]
s = point3d(l, size=5)
show(s, aspect_ratio=1)
</code></pre>
<p>I noticed that the last two lines take incredibly long each.</p>
<p>Then, after the <code>show</code>, when I try to interact with the graphic, it is blank. I can even show the boundbox and axes, but the plot is nowhere to be seen.</p>
<p>If I change to <code>[1 .. 100]</code>, everything works as intended, but this amount of points is not enough.</p>
<p>What should I do to accomplish effectively my goal?</p>
<p>I am using SAGE 8.1, installed on macOS via brew, after running <code>notebook()</code> on the command line and using the browser-based notebook.</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/?comment=44288#post-id-44288Maybe I'm naive but I can imagine it takes a while to plot 'just' 10,000 points in 3d. Your code works on my installation. Maybe try a different viewer: e.g. `s.show(viewer='threejs')`Thu, 15 Nov 2018 06:42:33 -0600http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/?comment=44288#post-id-44288Answer by tmonteil for <p>Hi,</p>
<p>First of all, I am new to SAGE, and only started using it today.</p>
<p>I want to plot 100 000 random 3D points in SAGE, and it takes a LOT of time just to plot 10 000 points.</p>
<p>This is the code I have:</p>
<pre><code>def random_point(): return (random(), random(), random())
l = [random_point() for k in [1 .. 10000]]
s = point3d(l, size=5)
show(s, aspect_ratio=1)
</code></pre>
<p>I noticed that the last two lines take incredibly long each.</p>
<p>Then, after the <code>show</code>, when I try to interact with the graphic, it is blank. I can even show the boundbox and axes, but the plot is nowhere to be seen.</p>
<p>If I change to <code>[1 .. 100]</code>, everything works as intended, but this amount of points is not enough.</p>
<p>What should I do to accomplish effectively my goal?</p>
<p>I am using SAGE 8.1, installed on macOS via brew, after running <code>notebook()</code> on the command line and using the browser-based notebook.</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/?answer=44290#post-id-44290This is not very surprising, since the `plot3d` returns a sum of `Point` object primitives, instead of a single primitive, each one will send a one-line string to jmol, see https://git.sagemath.org/sage.git/tree/src/sage/plot/plot3d/shapes2.py
A possible workaround (for 10000 points, not 100000) is to use ployly: install it from a terminal:
sage -pip install plotly
and then do something like (slightly modified from plotly's website to be run on your own worksheet):
import plotly
plotly.offline.init_notebook_mode(connected=True)
from plotly.offline import iplot
import plotly.plotly as py
import plotly.graph_objs as go
# Create random data with numpy
import numpy as np
N = 10000
random_x = np.random.randn(N)
random_y = np.random.randn(N)
random_z = np.random.randn(N)
trace = go.Scatter3d(
x = random_x,
y = random_y,
z = random_z,
mode = 'markers'
)
data = [trace]
iplot(data)
Thu, 15 Nov 2018 07:47:08 -0600http://ask.sagemath.org/question/44286/plotting-10k-random-3d-points/?answer=44290#post-id-44290