wxmplot matplotlib wxpython 互动散点图

0 投票
1 回答
872 浏览
提问于 2025-04-17 13:31

这是我的代码

    #!/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()

一开始有一个窗口,上面有一个菜单栏。你可以从下拉菜单中选择“加载蛋白质”,这样当前的窗口就会消失,然后会弹出一个新的窗口。接着你加载想要的数据,然后点击“确定”。按理说,这时应该会出现一个图表,但实际上并没有。我刚开始学Python,所以不太确定哪里出了问题。
我用的图表库是wxmplot,我觉得它和matplotlib有关。我觉得我的问题可能是窗口之间搞混了,或者类似的情况。
如果有人能帮忙,我会非常感激。
谢谢!

1 个回答

0

当你在把matplotlib和图形用户界面(GUI)工具结合在一起时,常常会遇到一些问题,这些问题通常和matplotlib的后端设置有关。因为你在写一个wx应用程序,我建议你试试“WXAgg”或者“WX”这两种后端设置。

撰写回答