pythonmatplotlibmatplotlib-3d

Additional axis when replotting 3D figure using 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')

enter image description here

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()

enter image description here

Any ideas? I'm going in circles right now!


Solution

  • 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:

    self.axes.get_xaxis().set_visible(False)
    self.axes.get_yaxis().set_visible(False)
    

    This seems to be one way at least of removing the 2D labels from 3D plots if they appear.