Skip to content Skip to sidebar Skip to footer

Python Plotly Slow Loading Of Mesh3d Plot

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

Solution 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)

Post a Comment for "Python Plotly Slow Loading Of Mesh3d Plot"