我正在为在matplotlib中制作3D散点图的接口编写代码,并希望从Python脚本中访问数据。对于2D散点图,我知道操作步骤应该是:
import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
h = ax.scatter(x,y,c=c,s=15,vmin=0,vmax=1,cmap='hot')
data = h.get_offsets()
通过上述代码,我知道数据将是一个用我的 (x,y)
数据填充的 (N,2)
numpy 数组。当我尝试对三维数据执行相同的操作时:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
h = ax.scatter(x,y,z,c=c,s=15,cmap='hot',vmin=0,vmax=1)
data = h.get_offsets()
生成的data
变量仍然是一个(N,2)
的numpy数组,而不是(N,3)
的numpy数组。 data
的内容不再与我的输入数据匹配;我假设data
是由我的三维数据生成的二维投影,但我真的想访问用于生成散点图的三维数据。这可行吗?
._offsets3d
来更新/更改绘制的数据? - James Robertsax
来访问这些数据吗? - todayax.collections[0]._offsets3d
来使用ax
访问它。 - today