(Mac OSX 10.10.5)
我可以从matplotlib网站复制http://matplotlib.org/gallery.html#mplot3d的3D散点图示例代码http://matplotlib.org/examples/mplot3d/scatter3d_demo.html,但情节呈现为静态图像.我无法点击图表并动态旋转以查看3D绘图数据.
我使用示例代码实现了静态3D绘图 - 使用(a)终端内的ipython,(b)终端内的ipython笔记本,以及(c)从Anaconda启动器启动的ipython笔记本.
我想我错过了一些非常基本的步骤作为假设的知识.
在过去的学习中,plotting已经打开了一个GUI Python App,它有一个图形查看器.(下面显示的代码中的解决方案2打开了这个.)也许我需要知道将输出图导出到该显示方法的代码?(是的,使用%matplotlib(仅)作为没有内联或笔记本的第一行,如下面代码块中的注释所示.)
作为ipython笔记本中的一个例子:
# These lines are comments
# Initial setup from an online python notebook tutorial is below.
# Note the first line "%matplotlib inline" this is how the tutorial has it.
# Two solutions 1. use: "%matplotlib notebook" graphs appear dynamic in the notebook.
# 2. use: "%matplotlib" (only) graphs appear dynamic in separate window.
# ( 2. is the best solution for detailed graphs/plots. …Run Code Online (Sandbox Code Playgroud) 我正在探索mpld3库,无法弄清楚如何创建3D散点图.使用Matplotlib,我会这样做:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1],[5],[7])
plt.show()
Run Code Online (Sandbox Code Playgroud)
同样,用mpld3我试过(在Jupyter笔记本中):从mpl_toolkits.mplot3d导入matplotlib.pyplot作为plt导入Axes3D导入mpld3
mpld3.enable_notebook()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1],[5],[7])
mpld3.display(fig)
Run Code Online (Sandbox Code Playgroud)
我得到了错误
TypeError: array([ 0.94, 1.06]) is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
这是完整的错误日志:
Traceback (most recent call last) <ipython-input-26-54fc4a65da87> in <module>()
6 N = 50
7 ax.scatter([1],[5],[7])
----> 8 mpld3.display(fig)
/usr/local/lib/python2.7/dist-packages/mpld3/_display.pyc in display(fig, closefig, local, **kwargs)
288 if closefig:
289 plt.close(fig)
--> 290 return HTML(fig_to_html(fig, **kwargs))
291
292
/usr/local/lib/python2.7/dist-packages/mpld3/_display.pyc in fig_to_html(fig, d3_url, mpld3_url, …Run Code Online (Sandbox Code Playgroud)