我与python一起使用,在我提取数千点时,我会在Mesh3D图的低性能中挣扎。我尝试绘制1500个立方体,但是加载绘图的HTML页面需要3分钟。有没有办法加快渲染的速度?激活GPU或类似的东西?还是有其他选项,例如plitly中的散点和散点?
这是我的代码:
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
)
感谢您的答案!
编辑:
我想主要的问题不是渲染本身,因为加载过程完成后,情节相互作用。
我试图分析创建的绘图HTML页面,并且有一个huuuuuuuuge脚本标签需要太多时间,以至于所有数据点都包含在内...怪异...仍然不知道如何处理。
编辑2:
长加载时间的问题是每个Mesh3d的多生成立方体。我可以在网格3D图中创建多个立方体,以便创建一个mesh3d吗?
x,y和z只是节点坐标的列表,i,j,k是连接列表。因此,当然您可以在每个Mesh3D跟踪中放置多个立方体(由于每个立方体都有6个侧面,因此您已经在每个Mesh3D跟踪中都放置了多个网格元素。,z,i,j,k。这样:
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)