0

I use Plotly with python and I struggle with the low performance of mesh3D plots as I draw thousands of points. I try to plot 1500 cubes, but it takes 3 minutes to load the plot's html page. Is there a way to speed up rendering? Activating gpu or something like that? Or is there another option of mesh3D like Scatter and Scattergl in Plotly?

Here is my code:

import plotly.offline as po
import plotly.graph_objs as go

def cubes(x=None, y=None, z=None, mode='', db=None):
size = 0.05
data = []
for index in range(len(x)):
    cube = go.Mesh3d(
        x=[x[index] - (size), x[index] - (size), x[index] + (size), x[index] + (size), x[index] - (size), x[index] - (size), x[index] + (size),
           x[index] + (size)],
        y=[y[index] - (size), y[index] + (size), y[index] + (size), y[index] - (size), y[index] - (size), y[index] + (size), y[index] + (size),
           y[index] - (size)],
        z=[z[index] - (size), z[index] - (size), z[index] - (size), z[index] - (size), z[index] + (size), z[index] + (size), z[index] + (size),
           z[index] + (size)],
        i=[7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2],
        j=[3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
        k=[0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
        showscale=True
    )
    data.append(cube)

layout = go.Layout(
    xaxis=go.XAxis(
        title='x'
    ),
    yaxis=go.YAxis(
        title='y'
    )
)

fig = go.Figure(
    data=data,
    layout=layout
)
po.plot(
    fig,
    filename='cubes.html',
    auto_open=True
)

Thanks for answers!

EDIT:

I guess the main problem is not the rendering itself, because after loading process is finished the plot interactes perfectly.

I tried to analyze the created plotly html page and there is one huuuuuuuuge script tag that takes so much time that where all data points are included... weird... Still have no idea how to handle that.

EDIT 2:

The problem with the long loading time is the multiple generation of cubes for each Mesh3d. Can I create multiple cubes in a Mesh3d diagram so that only one Mesh3d is created?

2
  • Not really a direct answer, and at the risk of obscuring some of the information you wish to convey, perhaps take a smaller random sample of the points? Commented Apr 24, 2018 at 14:35
  • Taking a small number of points loading is gonna be faster... but that is not a quite good solution :D Commented Apr 25, 2018 at 9:45

1 Answer 1

1

x, y and z are just lists of nodal coordinates, and i, j, k are lists of connectivity. So of course you can put multiple cubes in each Mesh3d trace (you already are putting multiple mesh elements in each Mesh3d trace since each of your cubes has 6 sides.) So instead of adding additional traces, add additional coordinates and indices into x,y,z,i,j,k. Like this:

def cubes(x=None, y=None, z=None, mode='', db=None):
    size = 0.05
    data = []
    xx=[]
    yy=[]
    zz=[]
    i=[]
    j=[]
    k=[]

    for index in range(len(x)):
        xx+=[x[index] - (size), x[index] - (size), x[index] + (size), x[index] +   
(size), x[index] - (size), x[index] - (size), x[index] + (size), x[index] + (size)]
        yy+=[y[index] - (size), y[index] + (size), y[index] + (size), y[index] - 
(size), y[index] - (size), y[index] + (size), y[index] + (size), y[index] - (size)]
        zz+=[z[index] - (size), z[index] - (size), z[index] - (size), z[index] - 
(size), z[index] + (size), z[index] + (size), z[index] + (size), z[index] + (size)]
        i+=[index*8+7, index*8+0, index*8+0, index*8+0, index*8+4, index*8+4, 
index*8+6, index*8+6, index*8+4, index*8+0, index*8+3, index*8+2]
        j+=[index*8+3, index*8+4, index*8+1, index*8+2, index*8+5, index*8+6, 
index*8+5, index*8+2, index*8+0, index*8+1, index*8+6, index*8+3]
        k+=[index*8+0, index*8+7, index*8+2, index*8+3, index*8+6, index*8+7, 
index*8+1, index*8+1, index*8+5, index*8+5, index*8+7, index*8+6]

    cube = go.Mesh3d(x=xx,y=yy,z=zz,i=i,j=j,k=k,showscale=True)
    data.append(cube)

    layout = go.Layout(xaxis=go.XAxis(title='x'),yaxis=go.YAxis(title='y'))

    fig = go.Figure(data=data,layout=layout)
    po.plot(fig,filename='cubes2.html',auto_open=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.