(Mac OSX 10.10.5)
我可以从matplotlib网站mplot3d复制示例代码,用于绘制3D散点图scatter3d_demo.py,但是图表呈现为静态图像。我无法点击图表并动态旋转以查看3D绘制的数据。
我已经使用示例代码实现了静态3D绘图 - 使用(a)从终端中的ipython,(b)从终端中的ipython笔记本,以及(c)从Anaconda启动器启动的ipython笔记本。
我认为我缺少一些非常基本的步骤,作为假定的知识。
在过去的学习中,绘图已经打开了一个GUI Python应用程序,其中包含一个图形查看器。(下面代码中的解决方案2打开此应用程序。)也许我需要知道将输出图导出到该显示方法的代码? (是的,请使用%matplotlib(仅)作为第一行,不要使用inline或notebook,如下面代码块中的注释所示。)
例如,在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. )
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
pd.set_option('html',False)
pd.set_option('max_columns',30)
pd.set_option('max_rows',10)
# What follows is a copy of the 3D plot example code.
# Data is randomly generated so there is no external data import.
def randrange(n, vmin, vmax):
return (vmax-vmin)*np.random.rand(n) + vmin
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -60, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 50)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
有人能够确定我缺少什么吗?
查看Python 3.3.6文档,第25.1节,也许是tkinter包...
tkinter包(“Tk界面”)是Tk GUI工具包的标准Python接口。Tk和tkinter都可在大多数Unix平台以及Windows系统上使用。
我认为这与GUI程序的开发有关,所以我不确定这是否相关。(正确,这对解决方案不需要。)
ax.mouse_init()
的调用。 - user3419537