pythonmatplotlibwxpythonwxnotebook

Matplotlib canvas doesn't embed in wx panel


I'm writing a class to embed some common configurations of graphs in a wx Notebook tab, but I'm running into a strange issue. When I try to add wx.Panel with the FigureCanvas, instead it floats the figure in another window entirely.

example

The odd thing is, the graph window resizes when I resize the main window. The figure comes out the correct size, just not in the right window.

My code is here. I can't see what I'm doing wrong, I've embedded matplotlib in wx before, but never in a Notebook. I can get it to embed on a simple GUI by itself just fine, just not in the tabs.


Solution

  • Try:

    1. Make GraphTab a wxPanel rather than a wxFrame
    2. Set all GraphTab to have nb as the parent (currently your first one has self as the parent.

    I'm not sure whether this is everything, but it's a start.