Ask Your Question
1

Plotting > 10k random 3D points

asked 2018-11-15 02:34:52 +0100

Kayvlim gravatar image

updated 2019-01-04 11:39:17 +0100

FrédéricC gravatar image

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!

edit retag flag offensive close merge delete

Comments

Maybe 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')

rburing gravatar imagerburing ( 2018-11-15 13:42:33 +0100 )edit

@rburing : even the construction of s takes time, not only the jmol plotting.

tmonteil gravatar imagetmonteil ( 2018-11-15 14:47:49 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2018-11-15 14:47:08 +0100

tmonteil gravatar image

updated 2021-05-31 20:20:02 +0100

This is not very surprising, since the plot3d returns a sum of Pointobject primitives, instead of a single primitive, each one will send a one-line string to jmol, see https://git.sagemath.org/sage.git/tre...

A possible workaround (for 10000 points, not 100000) is to use plotly: 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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-11-15 02:34:52 +0100

Seen: 535 times

Last updated: May 31 '21