我需要将一个可旋转的3D绘图导出到HTML,就像WriteWebGL does in R一样,但是要从Python / matplotlib导出。
当在Jupyter笔记本中运行时,您可以生成一个交互式绘图,如下所示:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
...
ax.scatter3D(xdata, ydata, zdata, c=zdata, cmap='Greens');(此示例here的源代码)
如上所述,3D绘图可以由用户旋转。如何将这种交互性从Python导出为HTML?
发布于 2020-09-28 22:48:52
一定要是matplotlib吗?你可以使用plotly来实现这一点。
这里有一个简单的例子。这将修改一个名为test.html的现有空文件,然后您可以在web浏览器中打开该文件以使用交互式3D绘图。
import plotly.graph_objects as go
import numpy as np
import plotly.express as px
# Helix equation
t = np.linspace(0, 20, 100)
x, y, z = np.cos(t), np.sin(t), t
fig = go.Figure(data=[go.Scatter3d(
x=x,
y=y,
z=z,
mode='markers',
marker=dict(
size=12,
color=z, # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8
)
)])
# tight layout
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0))
fig.write_html("test.html") #Modifiy the html file
fig.show()https://stackoverflow.com/questions/64104189
复制相似问题