使用 canvas.draw() 重新绘制 3D 图形时的附加轴
我在使用 Matplotlib 重新绘制一些 3D 数据时遇到了一个非常简单的问题。最初,我在画布上有一个带有 3D 投影的图形:
self.fig = plt.figure()
self.canvas = FigCanvas(self.mainPanel, -1, self.fig)
self.axes = self.fig.add_subplot(111, projection='3d')
然后我添加一些数据并使用画布.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()
有什么想法吗?我现在正在兜圈子!
I have what is probably a very simple problem replotting some 3D data using Matplotlib. Initially, I have an figure with a 3D projection on a canvas:
self.fig = plt.figure()
self.canvas = FigCanvas(self.mainPanel, -1, self.fig)
self.axes = self.fig.add_subplot(111, projection='3d')
I then add some data and use canvas.draw() to update. The plot itself updates as expected, but I get additional 2D axis on the outside of the figure (-0.05 to 0.05) and I can't work out how to stop it:
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()
Any ideas? I'm going in circles right now!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
mpl_toolkits.mplot3d.art3d.Patch3DCollection< 的
remove
方法代替axes.clear()
+fig.add_subplot
/code> object:如果你仍然有问题,你可以使用这个:
Instead of
axes.clear()
+fig.add_subplot
, use theremove
method of thempl_toolkits.mplot3d.art3d.Patch3DCollection
object:If you still have problems you can play with this:
Joquin 的建议效果很好,并强调我可能一开始就以错误的方式进行策划。然而,为了完整起见,我最终发现您可以简单地通过使用来摆脱 2D 轴:
这似乎是至少从 3D 图中删除 2D 标签(如果它们出现)的一种方法。
Joquin's suggestions worked well and highlighted that I was probably going about plotting the wrong way to start with. However, for the sake of completeness, I eventually found that you can get rid of the 2D axis simply by using:
This seems to be one way at least of removing the 2D labels from 3D plots if they appear.