如何解决我无法显示带有参照网格的值的图形
我正在创建一个具有两个面板的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 举报,一经查实,本站将立刻删除。