How to enable rotation in Axes3D (matplotlib) built into PyQt4 widget?

I use the approach shown in the following questions to embed Axes3D in a PyQt4 widget:

Qt4 + mplot3d of matplotlib

When starting the application, I can no longer rotate the axes with the mouse. What do I need to do to turn the turn back on?

+1
source share
3 answers

Each time you call something like Axes3D.clear() , you need to call Axes3D.mouse_init() to re-enable the mouse.

This seems to be undocumented, but it works for me! Source

+1
source

I had the same problem and it was solved after deep debugging. The problem is the inconsistency of the canvas instances. In the sample code, a shape is first created that automatically provides the shape with a canvas instance. Then axes are added to the figure, and then the canvas of the figure is replaced by another canvas, which can be used as a QWidget .

But the Axes3D constructor adds callback functions to its shape to implement the rotation function. So, if after this the canvas is replaced, the connection with the rotation functions is lost.

Perhaps this is enough to just call FigureCanvas.__init__() before adding axes to the figure, but I have not tried this.

My working solution is a little different: first I call matplotlib.use("Qt4Agg") to set the correct backend. Then I draw the shapes with fig = matplotlib.pyplot.figure() , which ensures that they already contain the right canvas, and then add Axes3D to them. I access the canvas simply as a fig.canvas data fig.canvas and use it as a QWidget . It is also important to call QtGui.QApplication() before building any shape.

0
source

I had a similar problem, but my axles did not appear. I called FigureCanvas.__init__() , then added axes to the figure, calling self.ax = self.fig.add_subplot(111, projection='3d') , as recommended by Björn

0
source

Source: https://habr.com/ru/post/951829/


All Articles