本文介绍了wx.Panel 上的 PlotCanvas?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 wx.lib.plot.PlotCanvas
模块时遇到困难,无法将其显示在面板中.有人可以帮我理解我做错了什么吗?
I'm having difficulties with the wx.lib.plot.PlotCanvas
module, getting it to display in a panel. Can someone please help me understand what I'm doing wrong?
#!/usr/bin/python
import wx
import logging
import wx.lib.plot as plot
class PlotCanvasExample(wx.Panel):
def __init__(self, parent, id, size):
''' Initialization routine for the this panel.'''
wx.Panel.__init__(self, parent, id, style=wx.BORDER_NONE, size=desiredSize)
self.data = [(1,2), (2,3), (3,5), (4,6), (5,8), (6,8), (10,10)]
canvas = plot.PlotCanvas(self, size=desiredSize)
line = plot.PolyLine(self.data, legend='', colour='pink', width=2)
gc = plot.PlotGraphics([line], 'Line Graph', 'X Axis', 'Y Axis')
canvas.Draw(gc, xAxis=(0,15), yAxis=(0,15))
if __name__ == '__main__':
''' Simple main program to display this panel. '''
# Create a simple wxFrame to insert the panel into
desiredSize = wx.Size(300,200)
app = wx.App()
frame = wx.Frame(None, -1, 'PlotCanvasExample', size=desiredSize)
example = PlotCanvasExample(frame, -1, size=desiredSize)
frame.Show()
app.MainLoop()
推荐答案
这是通过子类化 PlotCanvas 来工作的.我不把它放在面板中而是直接放在框架中
This works by subclassing PlotCanvas.I do not put it in a panel but directly in the Frame
!/usr/bin/python
import wx
import logging
import wx.lib.plot as plot
class PlotCanvasExample(plot.PlotCanvas):
def __init__(self, parent, id, size):
''' Initialization routine for the this panel.'''
plot.PlotCanvas.__init__(self, parent, id, style=wx.BORDER_NONE, size=desiredSize)
self.data = [(1,2), (2,3), (3,5), (4,6), (5,8), (6,8), (10,10)]
line = plot.PolyLine(self.data, legend='', colour='pink', width=2)
gc = plot.PlotGraphics([line], 'Line Graph', 'X Axis', 'Y Axis')
self.Draw(gc, xAxis=(0,15), yAxis=(0,15))
class MyFrame(wx.Frame):
def __init__(self, parent, id ,size):
wx.Frame.__init__(self, parent, id, size=desiredSize)
sizer = wx.BoxSizer(wx.VERTICAL)
self.canvas = PlotCanvasExample(self, 0, size)
sizer.Add(self.canvas, 1, wx.EXPAND, 0)
self.SetSizer(sizer)
self.Layout()
if __name__ == '__main__':
''' Simple main program to display this panel. '''
# Create a simple wxFrame to insert the panel into
desiredSize = wx.Size(300,200)
app = wx.PySimpleApp()
frame = MyFrame(None, -1, size=desiredSize)
frame.Show()
app.MainLoop()
这篇关于wx.Panel 上的 PlotCanvas?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!