我有一个可能是一个非常简单的问题,使用Matplotlib重新绘制一些3D数据。最初,我在画布上有一个3D投影的图形:
self.fig = plt.figure()
self.canvas = FigCanvas(self.mainPanel, -1, self.fig)
self.axes = self.fig.add_subplot(111, projection='3d')
然后我添加一些数据并使用canvas.draw()进行更新。图本身按预期更新,但我在图的外部获得了额外的2D轴(-0.05至0.05),我无法解决如何停止它:
self.axes.clear()
self.axes = self.fig.add_subplot(111, projection='3d')
xs = np.random.random_sample(100)
ys = np.random.random_sample(100)
zs = np.random.random_sample(100)
self.axes.scatter(xs, ys, zs, c='r', marker='o')
self.canvas.draw()
有什么办法吗?我现在在兜圈子!
2条答案
按热度按时间ztyzrc3y1#
使用
mpl_toolkits.mplot3d.art3d.Patch3DCollection
对象的remove
方法,而不是axes.clear()
+fig.add_subplot
:如果你仍然有问题,你可以玩这个:
f45qwnt82#
Joquin的建议很有效,并强调了我可能会以错误的方式开始绘制。然而,为了完整起见,我最终发现您可以通过使用以下命令来摆脱2D轴:
这似乎至少是一种从3D图中删除2D标签的方法,如果它们出现的话。