NavigationToolbar2Wx with mplot3d

Hi,

I have two questions about using NavigationToolbar2Wx with mplot3d.

1/ Initially the 3D scatter plot will rotate as usual with a mouse, but after selecting the ‘pan’ or ‘zoom’ buttons the plot responds with some
confusion. How can I restore it to rotation only, i.e. disconnect the zoom or pan behaviour?

2/ When using the ‘save’ button I get different behaviours depending on the backend. With ‘WXAgg’ the saved png image shows only the axes, not
the scatter points. The scatter points and axes do appear correctly in a pdf file. Using the ‘WX’ backend gives both scatter points and axes for the png file.

My full application has a mix of 2D and 3D plots (separate notebooks) and it would be preferable for users if all plots could usedthe common toolbar.

I see this behaviour running matplotlib 1.0.1 with Python 2.6.6 and wxPython 2.8.11.0 under Windows XP with the example below.

···

#-----------------------------------------------------------------------------------

adapted from example code “embedding_in_wx2.py”

import numpy as np

import matplotlib

uncomment the following to use wx rather than wxagg

#matplotlib.use(‘WX’)

#from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas

comment out the following to use wx rather than wxagg

matplotlib.use(‘WXAgg’)

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

from matplotlib.backends.backend_wx import NavigationToolbar2Wx

from matplotlib.figure import Figure

from mpl_toolkits.mplot3d import Axes3D

import wx

class CanvasFrame(wx.Frame):

def __init__(self):

    wx.Frame.__init__(self,None,-1,

                     'CanvasFrame',size=(550,350))

    self.SetBackgroundColour(wx.NamedColor("WHITE"))

    self.figure = Figure()

    self.canvas = FigureCanvas(self, -1, self.figure)

    self.axes = Axes3D(self.figure)

    xs = np.random.rand(100)

    ys = np.random.rand(100)

    zs = np.random.rand(100)

    self.axes.scatter(xs, ys, zs)

    self.sizer = wx.BoxSizer(wx.VERTICAL)

    self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)

    self.SetSizer(self.sizer)

    self.Fit()

    self.add_toolbar()  # comment this out for no toolbar

def add_toolbar(self):

    self.toolbar = NavigationToolbar2Wx(self.canvas)

    self.toolbar.Realize()

    if wx.Platform == '__WXMAC__':

        # Mac platform (OSX 10.3, MacPython) does not seem to cope with

        # having a toolbar in a sizer. This work-around gets the buttons

        # back, but at the expense of having the toolbar at the top

        self.SetToolBar(self.toolbar)

    else:

        # On Windows platform, default window size is incorrect, so set

        # toolbar width to figure width.

        tw, th = self.toolbar.GetSizeTuple()

        fw, fh = self.canvas.GetSizeTuple()

        # By adding toolbar in sizer, we are able to put it at the bottom

        # of the frame - so appearance is closer to GTK version.

        # As noted above, doesn't work for Mac.

        self.toolbar.SetSize(wx.Size(fw, th))

        self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)

    # update the axes menu on the toolbar

    self.toolbar.update()

def OnPaint(self, event):

    self.canvas.draw()

class App(wx.App):

def OnInit(self):

    'Create the main window and insert the custom frame'

    frame = CanvasFrame()

    frame.Show(True)

    return True

app = App(0)

app.MainLoop()

#------------------------------------------------------------------------------------------------

Regards,

Keith


This electronic transmission and any documents accompanying this electronic transmission contain confidential information belonging to the sender. This information may be legally privileged. The information is intended
only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically
transmitted information is strictly prohibited.

Hi,

I have two questions about using NavigationToolbar2Wx with mplot3d.

1/ Initially the 3D scatter plot will rotate as usual with a mouse, but after selecting the ‘pan’ or ‘zoom’ buttons the plot responds with some confusion. How can I restore it to rotation only, i.e. disconnect the zoom or pan behaviour?

That is a bug that should be resolved in the upcoming release. Use the right mouse button for zooming instead. In the upcoming release, the zoom and pan button should have no effect on axes3d objects, if I remember correctly.

2/ When using the ‘save’ button I get different behaviours depending on the backend. With ‘WXAgg’ the saved png image shows only the axes, not the scatter points. The scatter points and axes do appear correctly in a pdf file. Using the ‘WX’ backend gives both scatter points and axes for the png file.

I dont use WxAgg regularly. I will use your code to test this.

Ben Root

···

On Wednesday, September 21, 2011, Keith Jones <K.Jones@…1546…> wrote:

I could not reproduce your problem with WxAgg backend on the development branch. I could only test on Linux, though. However, if there is a difference between platforms with WxAgg backend, then it is likely a Wx bug and not a mpl bug (although the fact that the Wx backend worked is odd).

We are putting out an RC of v1.1.0 later today. Could you try out that version within the next few days and let me know if it still happens for you?

Ben Root

···

On Wednesday, September 21, 2011, Benjamin Root <ben.root@…1304…> wrote:

On Wednesday, September 21, 2011, Keith Jones <K.Jones@…1546…> wrote:

Hi,

I have two questions about using NavigationToolbar2Wx with mplot3d.

1/ Initially the 3D scatter plot will rotate as usual with a mouse, but after selecting the ‘pan’ or ‘zoom’ buttons the plot responds with some confusion. How can I restore it to rotation only, i.e. disconnect the zoom or pan behaviour?

That is a bug that should be resolved in the upcoming release. Use the right mouse button for zooming instead. In the upcoming release, the zoom and pan button should have no effect on axes3d objects, if I remember correctly.

2/ When using the ‘save’ button I get different behaviours depending on the backend. With ‘WXAgg’ the saved png image shows only the axes, not the scatter points. The scatter points and axes do appear correctly in a pdf file. Using the ‘WX’ backend gives both scatter points and axes for the png file.

I dont use WxAgg regularly. I will use your code to test this.

Ben Root

Matplotlib 1.1 fixes the NavigationToolbar2Wx issue with saving the .png image.

Thanks for the excellent support.

Regards.

Keith

···

From: ben.v.root@…287…
[mailto:ben.v.root@…287…] On Behalf Of Benjamin Root
Sent: Saturday, 24 September 2011 2:59 a.m.
To: Keith Jones
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] NavigationToolbar2Wx with mplot3d

On Wednesday, September 21, 2011, Benjamin Root <ben.root@…1304…> wrote:

On Wednesday, September 21, 2011, Keith Jones <K.Jones@…1546…> wrote:

Hi,

I have two questions about using NavigationToolbar2Wx with mplot3d.

1/ Initially the 3D scatter plot will rotate as usual with a mouse, but after selecting the ‘pan’ or ‘zoom’ buttons the plot responds with some confusion. How can I restore it to rotation only, i.e. disconnect the zoom or pan behaviour?

That is a bug that should be resolved in the upcoming release. Use the right mouse button for zooming instead. In the upcoming release, the zoom and pan button should have no effect on axes3d objects, if I remember correctly.

2/ When using the ‘save’ button I get different behaviours depending on the backend. With ‘WXAgg’ the saved png image shows only the axes, not the scatter points. The scatter points and axes do appear correctly in a pdf file. Using the ‘WX’ backend gives
both scatter points and axes for the png file.

I dont use WxAgg regularly. I will use your code to test this.

Ben Root

I could not reproduce your problem with WxAgg backend on the development branch. I could only test on Linux, though. However, if there is a difference between platforms with WxAgg backend, then it is likely a Wx bug and not a mpl bug (although the fact that
the Wx backend worked is odd).

We are putting out an RC of v1.1.0 later today. Could you try out that version within the next few days and let me know if it still happens for you?

Ben Root


This electronic transmission and any documents accompanying this electronic transmission contain confidential information belonging to the sender. This information may be legally privileged. The information is intended
only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically
transmitted information is strictly prohibited.