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.\n" + 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

转载于:https://www.cnblogs.com/ityoung/p/5545748.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值