Using mplot3d inside traits ui

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using mplot3d inside traits ui

Amit Aides
Hello,

I am trying to use matplotlib's 3d plots inside a traits gui. I have
followed the example in:
http://code.enthought.com/projects/traits/docs/html/tutorials/traits_ui_scientific_app.html
I get a 3D plot but it is not interactive, i.e I can't rotate or zoom it
using the mouse. I attach the code.
Another issue that I notice is that the application doesn't terminate
when I close the gui window.
I have found the following thread in this mailing list but it didn't
help me.
https://mail.enthought.com/pipermail/enthought-dev/2012-June/031117.html

Does any one know how to make the plot interactive?

Thanks in advance,
Amit

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

mpl_figure_editor.py (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using mplot3d inside traits ui

Roan LaPlante
In order to do this you need to connect callbacks to the figure.  My program with an interactive matplotlib window does this in create_canvas (adapted from the same example tutorial from Gael that yours is).

thus, it looks something like

def create_canvas(self,parent):
    self.canvas=FigureCanvasWxAgg(panel,-1,fig)
    ....
    self.press_cid = self.canvas.mpl_connect('button_press_event', self._do_panning() )
    self.release_cid = self.canvas.mpl_connect('button_release_event', self._end_pan() )

def _do_panning(self,event):
    ax=self.canvas.figure.get_axes()[0]
    ax.set_navigate_mode('PAN')
    ax.start_pan(event.x, event.y, 1)
    self._pan(event)
   
def _pan(self,event):
    ax=self.canvas.figure.get_axes()[0]
    ax.drag_pan(1,event.key,event.x,event.y)
    self.canvas.draw()

def _end_pan(self,event):
    ax=self.canvas.figure.get_axes()[0]
    ax.end_pan()


Most of the callback setup from my program is very complicated and some of it overwrites matplotlib's default behavior which does the wrong thing, so I won't show it here -- but this is the basic idea; YMMV.

Take a look at http://matplotlib.org/users/event_handling.html, and mpl's functionality for the particular interactions you want.


On Sun, Jul 21, 2013 at 5:37 AM, Amit Aides <[hidden email]> wrote:
Hello,

I am trying to use matplotlib's 3d plots inside a traits gui. I have followed the example in: http://code.enthought.com/projects/traits/docs/html/tutorials/traits_ui_scientific_app.html
I get a 3D plot but it is not interactive, i.e I can't rotate or zoom it using the mouse. I attach the code.
Another issue that I notice is that the application doesn't terminate when I close the gui window.
I have found the following thread in this mailing list but it didn't help me.
https://mail.enthought.com/pipermail/enthought-dev/2012-June/031117.html

Does any one know how to make the plot interactive?

Thanks in advance,
Amit

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.




--
Roan LaPlante
Athinoula A. Martinos Center for Biomedical Imaging


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev