I'm using the approach shown in the following questions for embedding an Axes3D in a PyQt4 widget:
When starting the application, I can not rotate the axes via mouse movement anymore. What do I need to do to enable the rotation again?
I'm using the approach shown in the following questions for embedding an Axes3D in a PyQt4 widget:
When starting the application, I can not rotate the axes via mouse movement anymore. What do I need to do to enable the rotation again?
I had a similar problem, but my axes would not appear. I called
FigureCanvas.__init__()
then added the axes to the figure by callingself.ax = self.fig.add_subplot(111, projection='3d')
, as recommended by BjörnHere, in Python 3, after setting global variable self.ax I switched mouse rotating on by calling self.ax.mouse_init(). Perhaps it helps you.
Any time you call something like
Axes3D.clear()
, then to enable mouse rotation again you have to callAxes3D.mouse_init()
.Seems to be undocumented, but it works for me! Source
I had the same problem and solved it after deep debugging. The problem is an inconsistency of the canvas instances. The example code first constructs a figure which automatically provides the figure with a canvas instance. Then an axes will be added to the figure and then the figure's canvas replaced by another canvas which can be used as
QWidget
.But, an
Axes3D
constructor adds callback functions to its figure's canvas to implement the rotation feature. So, if the canvas is replaced after that, the connection to the rotation functions gets lost.Maybe it's enough to simply call
FigureCanvas.__init__()
before adding the axes to the figure, but I haven't tried that.My working solution is a bit different: First I call
matplotlib.use("Qt4Agg")
to set the correct backend. Next, I construct figures withfig = matplotlib.pyplot.figure()
which makes sure they already contain the right canvas and then add theAxes3D
to them. I access the canvas simply as data elementfig.canvas
and use it asQWidget
. It is also important to callQtGui.QApplication()
before constructing any figure.