Hi there
I am not 100% sure whether this is a bug or whether I do something
wrong. However, I have the problem that the __init__ of
NavigationToolbar2Wx does not take the parent of the wx.ToolBar as an
input parameter. Instead it takes a canvas, and assumes that the parent
of the canvas is the parent of the toolbar as well.
In my attached example however, the parent of the wx.ToolBar should be
PlotFrame, whereas the parent of the canvas should be PlotWindow. As a
result, the NavigationToolbar is not placed correctly in the frame, and
sometimes invisible.
The same problem was already reported here:
http://matplotlib.1069221.n5.nabble.com/NavigationToolbar2WxAgg-Buttons-Disappear-td38516.html
My python version is 2.7.5 and matplotlib version is 1.1.1rc2.
A simple backward compatible solution to this problem is adding an
optional frame parameter to the NavigationToolbar2Wx __init__ like this:
class NavigationToolbar2Wx(NavigationToolbar2, wx.ToolBar):
def __init__(self, canvas, frame=None, can_kill=False):
if frame=None:
wx.ToolBar.__init__(self, canvas.GetParent(), -1)
else:
wx.ToolBar.__init__(self, frame, -1)
NavigationToolbar2.__init__(self, canvas)
Could someone tell me whether this should be included into matplotlib
like this?
With best regards
Matthias Baur
import matplotlib
matplotlib.use('WXAgg')
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
import matplotlib.pyplot as plt
from matplotlib import gridspec
class PlotFrame(wx.Frame):
def __init__(self, parent=None, id_=wx.ID_ANY, size=(600, 600),**kwargs):
super(PlotFrame, self).__init__(parent, id_, size=size, **kwargs)
self.plot_window = PlotWindow(parent=self)
self.toolbar = NavigationToolbar(self.plot_window.canvas)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.toolbar, proportion=0, flag=wx.ALIGN_LEFT)
sizer.Add(self.plot_window, proportion=1, flag=wx.GROW)
self.SetSizer(sizer)
class PlotWindow(wx.Window):
def __init__(self, parent=None, id_=wx.ID_ANY, **kwargs):
super(PlotWindow, self).__init__(parent, id_, **kwargs)
self.parent = parent
self.dpi = 70
self.figure = plt.figure(figsize=(7.0, 7.0), dpi=self.dpi)
self.canvas = FigureCanvas(self, -1, self.figure)
self._init_plots()
def _init_plots(self):
gs = gridspec.GridSpec(2, 2, width_ratios=[3, 1], height_ratios=[3,1])
self.intensity_plot = plt.subplot(gs[0], xlabel=r"x points", ylabel="y points")
self.x_slice_plot = plt.subplot(gs[2])
self.y_slice_plot = plt.subplot(gs[1])
class App(wx.App):
def OnInit(self):
self.frame1 = PlotFrame(title="Plot Window", size=(600, 600))
self.frame1.Show()
return True
if __name__ == '__main__':
# main()
app = App(False)
app.MainLoop()
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel