Hi everyone, I've been trying to solve this problem for the last few
days without success. I am afraid that part of the problem is my own
lack of understanding of matplotlib/wx's inner workings, this is my
first attempt to a GUI-tool.

I am using th networkx (https://networkx.lanl.gov/wiki) package to
generate a graph, this graph is according to the API "a pylab friendly
function that will use the current pylab figure axes (e.g. subplot)."

I want to embed this graph in the wx main application window. I've
been trying to do this using the wxmpl-package
(http://agni.phys.iit.edu/~kmcivor/wxmpl/) which creates a wx.Panel
containing a matplotlib.Figure. What I cant manage to do is to get the
networkx-graph (figure? subplot?) into the panel created by wxmpl.

What _does_ work is getting an embedded matplot-graph into the wxPanel
however I cant get the figure created by networkx to be drawn there
instead of an empty one. I think using the set_figure() function would
be a obvious way to do it, but I can't get it to work.

I realise that the problem might not be related to matplotlib at all
but I was hoping someone could give me help/pointers to a solution.

I attatched an .py example that shows what I am trying to do (you will
need wx, matplotlib, wxmpl and networkx).
Thanks!
#example.py

import wx
import pylab as P
import networkx as NX
import wxmpl as wxmpl


class MainWindow(wx.Frame):

    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, wx.DefaultPosition, wx.Size(800,600))
        
        #Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        gpanel = wxmpl.PlotPanel(self, -1)
        vbox.Add(gpanel, 1, wx.EXPAND | wx.ALL, 10)
        
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(wx.Button(self, 10, 'Quit'), 0, wx.LEFT, 10)
        self.Bind(wx.EVT_BUTTON, self.OnQuit, id=10)
        vbox.Add(hbox, 0, wx.BOTTOM | wx.EXPAND, 10)
        
        fig = MakeGraph()
        Gtmp = gpanel.get_figure()
        Gtmp.set_figure(fig.GFig)
        #P.show()
        self.SetSizer(vbox)
        
    def OnQuit(self, event):
        self.Close()
        
        
class TestApp(wx.App):
    def OnInit(self):
        frame = MainWindow(None, -1, 'App')
        frame.Show(True)
        frame.Centre()
        return True

class MakeGraph:
    def __init__(self):
        self.Graph = NX.Graph()
        self.Graph.add_edge(1,2)
        self.Graph.add_edge(1,3)
        self.Graph.add_edge(2,3)
        self.DrawGraph()
    
    def DrawGraph(self):
        pos = NX.spectral_layout(self.Graph)
        NX.draw_networkx_nodes(self.Graph, pos, node_size=400)
        NX.draw_networkx_edges(self.Graph, pos, width=2)
        NX.draw_networkx_labels(self.Graph, pos, font_size=10, font_family='sans-serif')
    
        P.xticks([]) #no x-axis
        P.yticks([]) #no y-axis
        self.GFig = P.gcf()
    
app = TestApp(0)
app.MainLoop()

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to