我无法显示带有参照网格的值的图形

问题描述

我正在创建一个具有两个面板的GUI。一种是让用户输入日期和价格的网格。另一个是用于显示总费用的图表。

我想从panel1的网格单元中获取价值。但是,我在panel2中看不到任何图形。

请修复此代码,以便能够在网格中获取值并在panel2中创建线性图。

代码如下:

import wx
import wx.grid
import matplotlib
from matplotlib.backends.backend_wxagg import figureCanvasWxAgg
app = wx.App()

class MainFrame(wx.Frame): 
   def __init__(self,parent,title): 
      super().__init__(parent,title = title,size = (600,600))  
      self.InNotebook() 
         
   def InNotebook(self):    
      nb = wx.Notebook(self) 
      nb.AddPage(Panel1(nb),"Input Values")
      nb.AddPage(Panel2(nb),"Total Expense")
      self.Centre() 
      self.Show(True)

class Panel1(wx.Panel):
    def __init__(self,parent): 
      super(Panel1,self).__init__(parent)
      grid = wx.grid.Grid(self)
      grid.CreateGrid(5,2)
      
      grid.SetColLabelValue(0,"dates")
      grid.SetColLabelValue(1,"Prices")

      grid.SetCellValue(0,"20,21,23")
      grid.SetCellValue(0,1,"453,363,567" ) 

      
      grid.AutoSize()

class Panel2(wx.Panel):
    
    def __init__(self,parent): 
      super(Panel2,self).__init__(parent)

    def GetValue(self):
      value_dates = self.grid.GetCellValue(self,0)
      value_prices = self.grid.GetCellValue(self,1)
    
    def Graph(self):
        value_dates = self.grid.GetCellValue(self,0)
        value_prices = self.grid.GetCellValue(self,1)
        figure = matplotlib.figure.figure(self)
        self.canvas = figureCanvasWxAgg(self,wx.ID_ANY,figure)
        self.plot1 = figure.add_subplot(211,xlabel='dates',ylabel='expense')
        self.plot1.plot(value_dates,value_prices,'-',color=clr[num%len(clr)],label='[$]')
        self.plot1.legend(loc='upper right')
        self.canvas.draw()

MainFrame(None,"Total Expense")
app.MainLoop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)