wx.Panel 上的 PlotCanvas?

发布于 2024-12-07 09:41:40 字数 1165 浏览 1 评论 0原文

我在使用 wx.lib.plot.PlotCanvas 模块时遇到困难,无法将其显示在面板中。有人可以帮助我理解我做错了什么吗?

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

在此处输入图像描述

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()

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染年凉城似染瑾 2024-12-14 09:41:40

这是通过子类化 PlotCanvas 来实现的。
我没有将其放在面板中,而是直接放在框架中

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

在此处输入图像描述

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()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文