Re: [Matplotlib-users] Axes3d.mouse_init(), facing problems when embedding matplotlib 3d-projection into PyQt5 App
Ok, back from revision... The is no mix-up for the show command. The only explicit show() command is commented out in line 41. It can be deleted. But I haven't done that, yet. There are several bits of code which are remains of the design process since this is work in progress. Code cleaning will be done when the main functionality is in place. Back to addmpl where I embedded gui elements into the canvas. Taking out the matplotlib taskbar doesn't change a thing as I wrote earlier, but to make sure it doesn't bother the mainloop, it should be commented out. I may not put it back in, because I don't see the point in needing it. It was just to see if it's possible. But option 2 relinquishes that control to the developer's GUI app. You *cannot* use pyplot for option 2, which is what you are doing. Is that so? In line 116 I create the canvas, which is derived from matplotlib's backend's FigureCanvasQTAgg and given to the QWidget at line 119. That's the only part where both interact with each other. the rest is handle by matplotlib. The error message says that Axes3D.figure.canvas is 'None' and that's why mouse rotation is disabled.It's None because there is no content at that point, when it's passed to the QWidget. It's filled with content in line 38. So if matplotlib disables the mouse rotation by default, when the canvas is empty how do I prevent this disabling by default? If I can't, at what point do I have to pass the filled canvas to the QWidget? How does that impact the GUI itself? If I can't enable the mouse rotation by hand and I just can pass filled canvas around, do I have to build a work around with initialize it with an empty 2D canvas and replace it later with the filled 3D canvas? How's the mouse rotation activated then? In general, I wouldn't have to enable the rotation if it wouldn't be switch off for an empty canvas. I'm going to consult your book, now, for different ways of coping with such things... cheers,Christian -- A little learning never caused anyone's head to explode! Ein wenig Lernen hat noch niemandens Kopf zum Explodieren gebracht! On Tuesday, April 28, 2015 8:28 PM, Benjamin Root ben.r...@ou.edu wrote: One thing I see off the bat is your addmpl() method: ``` def addmpl(self, fig): #FigureCanvas.__init__(self, fig) self.canvas = FigureCanvas(fig) Axes3D.mouse_init(self, rotate_btn=1, zoom_btn=2) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.mplwindow, coordinates=True) self.mplvl.addWidget(self.toolbar) ``` You are calling Axes3D.mouse_init() on the Main object (that is `self`). That is completely wrong. It can only be called for the 3d axes objects. Also, what I see happening here is some mixing up of how to do embedding. There are two approaches to embedding. 1) you can embedded GUI elements into your canvas widget, or 2) you can embed your canvas widget into your GUI app. The important distinction between the two is who controls the mainloop. In option 1 (and in matplotlib in general), pyplot will create the GUI app for you automatically (it is completely transparent to you) and kicks it off upon call to show(). But option 2 relinquishes that control to the developer's GUI app. You *cannot* use pyplot for option 2, which is what you are doing. Rip out all of the pyplot stuff, and instantiate the Qt5 Figure object directly, and then obtain the axes objects from the figure object via calls to add_subplot(). You shouldn't even need to do the whole mouse_init() stuff. I now think this has nothing to do with Qt Designer. While I don't specifically cover qt5 in my book, I do make all of these distinctions very clear in chapter 5 of my book Interactive Applications using Matplotlib. Cheers! Ben Root On Tue, Apr 28, 2015 at 4:03 PM, Christian Ambros ambr...@ymail.com wrote: Hi Benjamin, I would do that if my task were my private stuff, but in this case it's work-related and my boss wants me to use the designer and he already set a deadline, which, I already knew, is set to tight. I told him before, that it would be just a try but he sold it to his boss after some pressure. You know how the bosses' bosses are, they don't get the idea that innovation can't be dictated. They don't understand the concept that software is written and doesn't come into existence out of nothing. Without PyQt5 it's working fine. I got the plots and they are gorgeous, but that doesn't help when presenting to the bosses. If I just would know how to activate the 3d-draw's mouse action again, by hand, than it has to last just some moments for the presentation, afterwards I have the time to examine and find a more robust solution. Thanks for the effort.cheers,Christian -- A little learning never caused anyone's head to explode! Ein wenig Lernen hat noch niemandens Kopf zum Explodieren gebracht! On Tuesday,
[Matplotlib-users] Testing - please ignore
-- One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Axes3d.mouse_init(), facing problems when embedding matplotlib 3d-projection into PyQt5 App
Christian (again, keeping things on-list), The entire point of the example was to provide a proof of concept and to show the absolute minimum needed to get mplot3d embedded. Please do not disregard it because I did not use Qt Designer. If I understand Qt Designer correctly, it merely provides additional widgets to be included in the app, so the figure really doesn't care about that stuff and should be completely orthogonal to our problem. When you run the example I gave you, it works without any need to call mouse_init(). The fact that it works without any call to mouse_init() proves that something is going very wrong in your code. The only reason for it to be called by the user is if the user managed to disable the user interactions and needs to restore it. That should never happen unless the user explicitly makes that happen. What I see in your code is you creating the axes before creating the figure canvas. Look at my example closely. The order of the commands matter. If you are creating axes objects in a figure, and then adding a canvas, you are overwriting the auto-generated canvas that was implicitly created when you added axes objects. That is why you are losing interactivity, because all of the original callbacks were being attached to the original canvas that you overwrote. This was also noted in the SO link that Thomas gave you. I hope that clarifies things for you, Ben Root On Wed, Apr 29, 2015 at 3:12 PM, Christian Ambros ambr...@ymail.com wrote: Nice, but not close to the task on hand, because no Qt Designer was used, so no gui-elements from there, no embedding! And that was the point to all this. But maybe I'v come up with a solution to my problem... Your remember the lines: *def main(argv):app = QtWidgets.QApplication(argv)mainwindow = Main()mainwindow.show()fig1 = Figure()#ax1f1 = fig1.add_subplot(111)fname='augtr_16MnCrS5.dat'arr = np.genfromtxt(fname, delimiter=' ', usecols=(0,4,25), missing_values={0:' '}, filling_values={0:0}, unpack=True) #ax1f1.plot(np.random.rand(20))#ax1f1.plot(arr(0,25))#fig = plt.figure()ax1f1 = fig1.add_subplot(111, projection='3d')Y, Z, X = arrax1f1.plot_wireframe(X, Y, Z, rstride=10, cstride=10) #plt.show()fig2 = Figure()ax1f2 = fig2.add_subplot(211) ax1f2.plot(Y, Z) #np.random.rand(10)ax2f2 = fig2.add_subplot(212) ax2f2.plot(Y, X)#np.random.rand(10)fig3 = Figure()ax1f3 = fig3.add_subplot(111)ax1f3.pcolormesh(np.random.rand(20,20)) mainwindow.addmpl(fig1)mainwindow.addfig('figure 1', fig1) mainwindow.addfig('figure 2', fig2)mainwindow.addfig('figure 3', fig3)#input()#mainwindow.rmmpl()#mainwindow.addmpl(fig2) #mainwindow.addfig('figure 2', fig2)sys.exit(app.exec_())* Let's take a look at the important part: *def main(argv):app = QtWidgets.QApplication(argv)mainwindow = Main()mainwindow.show()fig1 = Figure()#ax1f1 = fig1.add_subplot(111)fname='augtr_16MnCrS5.dat'arr = np.genfromtxt(fname, delimiter=' ', usecols=(0,4,25), missing_values={0:' '}, filling_values={0:0}, unpack=True) #ax1f1.plot(np.random.rand(20))#ax1f1.plot(arr(0,25))#fig = plt.figure()ax1f1 = fig1.add_subplot(111, projection='3d')Y, Z, X = arrax1f1.plot_wireframe(X, Y, Z, rstride=10, cstride=10) #plt.show()fig2 = Figure()ax1f2 = fig2.add_subplot(211) ax1f2.plot(Y, Z) #np.random.rand(10)ax2f2 = fig2.add_subplot(212) ax2f2.plot(Y, X)#np.random.rand(10)fig3 = Figure()ax1f3 = fig3.add_subplot(111)ax1f3.pcolormesh(np.random.rand(20,20)) mainwindow.addmpl(fig1)mainwindow.addfig('figure 1', fig1) mainwindow.addfig('figure 2', fig2)mainwindow.addfig('figure 3', fig3)#input()#mainwindow.rmmpl()#mainwindow.addmpl(fig2) #mainwindow.addfig('figure 2', fig2)sys.exit(app.exec_())* ... and skip the rest... if I just initialize the mouse upon the axis like this: fig1 = Figure() fname='augtr_16MnCrS5.dat' arr = np.genfromtxt(fname, delimiter=' ', usecols=(0,4,25), missing_values={0:' '}, filling_values={0:0}, unpack=True) ax1f1 = fig1.add_subplot(111, projection='3d') Y, Z, X = arr mainwindow.addmpl(fig1) ax1f1.mouse_init() ax1f1.plot_wireframe(X, Y, Z, rstride=10, cstride=10) than mouse rotation is back online, no warning, no error. As I asked at the beginning, it was just the right place where the mouse_init() has to be put. It bothered me so much that I dug into API again and searched for mouse_init(). Taking the error message into account, mouse rotation off I figured out that it's an axis problem. It's not the canvas which is rotated, it's all about the axis, so I found the usage for the mouse_init(). Thank you very much for all your effort and the patience to go this way with me. At
Re: [Matplotlib-users] Axes3d.mouse_init(), facing problems when embedding matplotlib 3d-projection into PyQt5 App
I think that this SO answer may be relevant: https://stackoverflow.com/questions/18259350/embed-an-interactive-3d-plot-in-pyside/18278457#18278457 On Wed, Apr 29, 2015 at 5:43 AM Christian Ambros ambr...@ymail.com wrote: Ok, back from revision... The is no mix-up for the show command. The only explicit show() command is commented out in line 41. It can be deleted. But I haven't done that, yet. There are several bits of code which are remains of the design process since this is work in progress. Code cleaning will be done when the main functionality is in place. Back to addmpl where I embedded gui elements into the canvas. Taking out the matplotlib taskbar doesn't change a thing as I wrote earlier, but to make sure it doesn't bother the mainloop, it should be commented out. I may not put it back in, because I don't see the point in needing it. It was just to see if it's possible. But option 2 relinquishes that control to the developer's GUI app. You *cannot* use pyplot for option 2, which is what you are doing. Is that so? In line 116 I create the canvas, which is derived from matplotlib's backend's FigureCanvasQTAgg and given to the QWidget at line 119. That's the only part where both interact with each other. the rest is handle by matplotlib. The error message says that Axes3D.figure.canvas is 'None' and that's why mouse rotation is disabled. It's None because there is no content at that point, when it's passed to the QWidget. It's filled with content in line 38. So if matplotlib disables the mouse rotation by default, when the canvas is empty how do I prevent this disabling by default? If I can't, at what point do I have to pass the filled canvas to the QWidget? How does that impact the GUI itself? If I can't enable the mouse rotation by hand and I just can pass filled canvas around, do I have to build a work around with initialize it with an empty 2D canvas and replace it later with the filled 3D canvas? How's the mouse rotation activated then? In general, I wouldn't have to enable the rotation if it wouldn't be switch off for an empty canvas. I'm going to consult your book, now, for different ways of coping with such things... cheers, Christian -- A little learning never caused anyone's head to explode! Ein wenig Lernen hat noch niemandens Kopf zum Explodieren gebracht! On Tuesday, April 28, 2015 8:28 PM, Benjamin Root ben.r...@ou.edu wrote: One thing I see off the bat is your addmpl() method: ``` def addmpl(self, fig): #FigureCanvas.__init__(self, fig) self.canvas = FigureCanvas(fig) Axes3D.mouse_init(self, rotate_btn=1, zoom_btn=2) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.mplwindow, coordinates=True) self.mplvl.addWidget(self.toolbar) ``` You are calling Axes3D.mouse_init() on the Main object (that is `self`). That is completely wrong. It can only be called for the 3d axes objects. Also, what I see happening here is some mixing up of how to do embedding. There are two approaches to embedding. 1) you can embedded GUI elements into your canvas widget, or 2) you can embed your canvas widget into your GUI app. The important distinction between the two is who controls the mainloop. In option 1 (and in matplotlib in general), pyplot will create the GUI app for you automatically (it is completely transparent to you) and kicks it off upon call to show(). But option 2 relinquishes that control to the developer's GUI app. You *cannot* use pyplot for option 2, which is what you are doing. Rip out all of the pyplot stuff, and instantiate the Qt5 Figure object directly, and then obtain the axes objects from the figure object via calls to add_subplot(). You shouldn't even need to do the whole mouse_init() stuff. I now think this has nothing to do with Qt Designer. While I don't specifically cover qt5 in my book, I do make all of these distinctions very clear in chapter 5 of my book Interactive Applications using Matplotlib. Cheers! Ben Root On Tue, Apr 28, 2015 at 4:03 PM, Christian Ambros ambr...@ymail.com wrote: Hi Benjamin, I would do that if my task were my private stuff, but in this case it's work-related and my boss wants me to use the designer and he already set a deadline, which, I already knew, is set to tight. I told him before, that it would be just a try but he sold it to his boss after some pressure. You know how the bosses' bosses are, they don't get the idea that innovation can't be dictated. They don't understand the concept that software is written and doesn't come into existence out of nothing. Without PyQt5 it's working fine. I got the plots and they are gorgeous, but that doesn't help when presenting to the bosses. If I just would know how to activate the 3d-draw's mouse action again, by hand, than it has to last just some moments for the presentation,
Re: [Matplotlib-users] Axes3d.mouse_init(), facing problems when embedding matplotlib 3d-projection into PyQt5 App
Here is a proof of concept (yes, it uses qt4... my work computer doesn't have qt5, but that should be a straight-forward modification to make). Note the complete lack of any call to mouse_init() and the complete lack of any use of pyplot (in fact, I commented it out to make the point that you shouldn't use pyplot *at all* when doing this sort of embedding). ``` import numpy as np #import matplotlib.pyplot as plt import sys from matplotlib.backends.qt4_compat import QtGui, QtCore from matplotlib.figure import Figure from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from mpl_toolkits.mplot3d import Axes3D if __name__ == '__main__': # Must come before any Qt widgets are made app = QtGui.QApplication(sys.argv) win = QtGui.QMainWindow() fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(1, 1, 1, projection='3d') xs = np.random.rand(25) ys = np.random.rand(25) zs = np.random.rand(25) ax.scatter(xs, ys, zs) win.resize(int(fig.bbox.width), int(fig.bbox.height)) win.setWindowTitle(Embedding with Qt) # Needed for keyboard events canvas.setFocusPolicy(QtCore.Qt.StrongFocus) canvas.setFocus() win.setCentralWidget(canvas) win.show() sys.exit(app.exec_()) ``` I hope this helps! Ben Root On Wed, Apr 29, 2015 at 5:38 AM, Christian Ambros ambr...@ymail.com wrote: Ok, back from revision... The is no mix-up for the show command. The only explicit show() command is commented out in line 41. It can be deleted. But I haven't done that, yet. There are several bits of code which are remains of the design process since this is work in progress. Code cleaning will be done when the main functionality is in place. Back to addmpl where I embedded gui elements into the canvas. Taking out the matplotlib taskbar doesn't change a thing as I wrote earlier, but to make sure it doesn't bother the mainloop, it should be commented out. I may not put it back in, because I don't see the point in needing it. It was just to see if it's possible. But option 2 relinquishes that control to the developer's GUI app. You *cannot* use pyplot for option 2, which is what you are doing. Is that so? In line 116 I create the canvas, which is derived from matplotlib's backend's FigureCanvasQTAgg and given to the QWidget at line 119. That's the only part where both interact with each other. the rest is handle by matplotlib. The error message says that Axes3D.figure.canvas is 'None' and that's why mouse rotation is disabled. It's None because there is no content at that point, when it's passed to the QWidget. It's filled with content in line 38. So if matplotlib disables the mouse rotation by default, when the canvas is empty how do I prevent this disabling by default? If I can't, at what point do I have to pass the filled canvas to the QWidget? How does that impact the GUI itself? If I can't enable the mouse rotation by hand and I just can pass filled canvas around, do I have to build a work around with initialize it with an empty 2D canvas and replace it later with the filled 3D canvas? How's the mouse rotation activated then? In general, I wouldn't have to enable the rotation if it wouldn't be switch off for an empty canvas. I'm going to consult your book, now, for different ways of coping with such things... cheers, Christian -- A little learning never caused anyone's head to explode! Ein wenig Lernen hat noch niemandens Kopf zum Explodieren gebracht! On Tuesday, April 28, 2015 8:28 PM, Benjamin Root ben.r...@ou.edu wrote: One thing I see off the bat is your addmpl() method: ``` def addmpl(self, fig): #FigureCanvas.__init__(self, fig) self.canvas = FigureCanvas(fig) Axes3D.mouse_init(self, rotate_btn=1, zoom_btn=2) self.mplvl.addWidget(self.canvas) self.canvas.draw() self.toolbar = NavigationToolbar(self.canvas, self.mplwindow, coordinates=True) self.mplvl.addWidget(self.toolbar) ``` You are calling Axes3D.mouse_init() on the Main object (that is `self`). That is completely wrong. It can only be called for the 3d axes objects. Also, what I see happening here is some mixing up of how to do embedding. There are two approaches to embedding. 1) you can embedded GUI elements into your canvas widget, or 2) you can embed your canvas widget into your GUI app. The important distinction between the two is who controls the mainloop. In option 1 (and in matplotlib in general), pyplot will create the GUI app for you automatically (it is completely transparent to you) and kicks it off upon call to show(). But option 2 relinquishes that control to the developer's GUI app. You *cannot* use pyplot for option 2, which is what you are doing. Rip out all of the pyplot stuff, and instantiate the Qt5 Figure object directly, and then obtain the axes objects from the figure object via calls to add_subplot(). You