wxmplot matplotlib wxpython交互式散点图

时间:2013-01-24 14:21:13

标签: python wxpython wxwidgets

这是我的代码

    #!/usr/bin/python
#

import sys
if not hasattr(sys, 'frozen'):
import wxversion
wxversion.ensureMinimal('2.8')

import wxmplot
import numpy
import wx
import os
import subprocess
import re
import wx.lib.plot as plot
import urllib2
from BeautifulSoup import BeautifulSoup
from wx.lib.pubsub import Publisher

""""""

#----------------------------------------------------------------------
def __init__(self, parent, size = (5000,5000)):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent, size = (5000,5000))
    self.frame = parent

    Publisher().subscribe(self.showFrame, ("show.mainframe"))
    menu=wx.MenuBar()
    file0 = wx.Menu()
    help0 = wx.Menu()
    Load=file0.Append(wx.NewId(),"Load Protein","Load from PDB File")
    parent.Bind(wx.EVT_MENU,self.load,Load)
    file0.Append(wx.NewId(),"Save")
    Close = file0.Append(wx.NewId(),"Quit")
    parent.Bind(wx.EVT_MENU,self.close,Close)
    help0.Append(wx.NewId(),"Help")
    help0.Append(wx.NewId(),"About")
    menu.Append(file0,"File")
    menu.Append(help0,"Help")
    parent.SetMenuBar(menu)
    self.pubsubText = wx.StaticText(self,-1," ", (5,150))        


def close(self,event):
    self.Close(True)

def showFrame(self, msg):
    """
    Shows the frame and shows the message sent in the
    text control
    """
    self.pubsubText.SetLabel("This is the Contact Map for the chain "+msg.data[0]+" in the PDB file "+msg.data[1])


self.data = number_list
    x   = numpy.arange(100)/20.0 + numpy.random.random(size=100)
    y   = numpy.random.random(size=len(x))
    def onlasso(data=None, selected=None, mask=None):
        print ':: lasso ', selected
        pframe = wxmplot.PlotFrame()
        pframe.scatterplot(x, y, title='Scatter Plot', size=15,xlabel='$ x\, \mathrm{(\AA)}$',ylabel='$ y\, \mathrm{(\AA^{-1})}$')
        pframe.panel.lasso_callback = onlasso
        pframe.write_message('WXMPlot PlotFrame example: Try Help->Quick Reference')
        pframe.Show()
frame=self.GetParent()
frame.Show()

########################################################################
class MainFrame(wx.Frame):

#----------------------------------------------------------------------
def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "PSP Solver")
    panel = MainPanel(self)

#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()

首先有一个框架,有一个菜单栏,然后​​从下拉菜单中选择加载Protein,这会使当前框架消失,然后弹出一个新框架,然后加载所需的数据然后按好。在此之后应该发生的是图形应该出现,但事实并非如此。我是python的新手所以不确定我哪里出错了。 对于图表,我使用的是wxmplot,我相信它与matplotlib有关。我认为我的问题是与框架或类似的混合。 任何帮助将不胜感激 干杯

1 个答案:

答案 0 :(得分:0)

通常在将matplotlib与GUI工具包集成时发生这种情况时,问题与matplotlib backend设置有关。由于您正在编写wx应用程序,我建议您尝试使用“WXAgg”或“WX”后端。