首页 > 解决方案 > 如何将 Matplotlib 交互式 3D 绘图导出为无需 Python 即可打开的格式(例如 HTML)?

问题描述

我想向非 python 用户发送 Matplotlib 交互式 3D 图,以便他们可以旋转和放大/缩小图形。例如,下面的代码会生成一个简单的 3D 条形图,但如果没有安装 Python,则无法读取。

我尝试使用 mpld3 函数(get TypeError: Object of type ndarray is not JSON serializable)使用 PyInstaller 编译并读取 pickle.dumb 文件(未显示图),使用上一个线程中建议的 libscript 模块(保存交互式 Matplotlib 数字)没有成功。

''''

from  mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')

xpos = [1,2,3,4,5,6,7,8,9,10]
ypos = [2,3,4,5,1,6,2,1,7,2]
zpos = [0,0,0,0,0,0,0,0,0,0]

dx = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
dy = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
dz = [1,2,3,4,5,6,7,8,9,10]


ax1.bar3d(xpos, ypos,zpos, dx, dy, dz, color = '#00ceaa')
plt.show()

''''

标签: pythonmatplotlib

解决方案


推荐阅读