• wxpython绘制折线图


    environment:win10 + eclipse + pydev + python2.7.11 + wxpython3.0.2

    code sample:

     1 #!/usr/bin/env python
     2 # -*- coding: UTF-8 -*-
     3  
     4 import wx
     5 import wx.lib.plot as plot
     6  
     7 class MyFrame(wx.Frame):
     8     def __init__(self):
     9         self.frame1 = wx.Frame(None, title="test", id=-1, size=(500, 300))
    10         self.panel1 = wx.Panel(self.frame1)
    11         self.panel1.SetBackgroundColour("white")
    12  
    13         Button1 = wx.Button(self.panel1, -1, "Update", (200,220))
    14         Button1.Bind(wx.EVT_BUTTON, self.redraw)
    15  
    16         plotter = plot.PlotCanvas(self.panel1)
    17         plotter.SetInitialSize(size=(500, 200))
    18  
    19         data= [[1, 10], [2, 5], [3,10], [4, 5]]
    20         line= plot.PolyLine(data, colour='red', width=1)
    21  
    22         gc= plot.PlotGraphics([line], 'Test', 'x', 'y')
    23         plotter.Draw(gc)
    24  
    25         self.frame1.Show(True)
    26  
    27  
    28     def redraw(self, event):
    29         plotter = plot.PlotCanvas(self.panel1)
    30         plotter.SetInitialSize(size=(500, 200))
    31  
    32         data2= [[1, 20], [2, 15], [3,20], [4, -10]]
    33         line= plot.PolyLine(data2, colour='red', width=1)
    34  
    35         gc= plot.PlotGraphics([line], 'Test', 'x', 'y')
    36         plotter.Draw(gc)
    37  
    38 app = wx.PySimpleApp()
    39 f = MyFrame()
    40 app.MainLoop()
    View Code

    error 1:raise ImportError("NumPy not found. " + msg)

    solution: run console with"cmd", and run 'pip install numpy'.

    error 2:TypeError: Required argument 'type' (pos 2) not found

    solution:that's A BUG with wx3.0.2! 

    patch the latest wx.lib.plot can totally solve that.

    url:https://github.com/wxWidgets/wxPython/commit/30bc07d80ae1c81d70b4de2daac62ecd7996d703

    now everything is fine!

    转载注明出处:http://www.cnblogs.com/ityoung/

    github: https://github.com/ityoung

  • 相关阅读:
    line-height 行高
    CSS菜单横竖布局要点
    鬼吹灯之精绝古城迅雷下载
    sublime less高亮插件
    Swiper说明&&API手册
    jQuery的deferred对象详解
    js中typeof与instanceof的不同用法
    js中apply方法的使用
    Javascript获取当前时间戳的方法
    json对象和json字符串转换方法
  • 原文地址:https://www.cnblogs.com/ityoung/p/5545748.html
Copyright © 2020-2023  润新知