Matplotlib 我能';t显示值引用到网格的图形
我正在创建一个有两个面板的GUI。一种是让用户输入日期和价格的网格。另一个是用于显示总费用的图表 我想从panel1中网格中的单元格中获取值。但是,我在panel2中看不到任何图表 请修复此代码,以便能够在网格中获取值,并在panel2中生成线性图 代码如下:Matplotlib 我能';t显示值引用到网格的图形,matplotlib,wxpython,Matplotlib,Wxpython,我正在创建一个有两个面板的GUI。一种是让用户输入日期和价格的网格。另一个是用于显示总费用的图表 我想从panel1中网格中的单元格中获取值。但是,我在panel2中看不到任何图表 请修复此代码,以便能够在网格中获取值,并在panel2中生成线性图 代码如下: import wx import wx.grid import matplotlib from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg app = wx.App
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, 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, 0)
value_prices = self.grid.GetCellValue(self, 0, 1)
def Graph(self):
value_dates = self.grid.GetCellValue(self, 0, 0)
value_prices = self.grid.GetCellValue(self, 0, 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()