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?