-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwxplot.py
More file actions
51 lines (45 loc) · 1.69 KB
/
wxplot.py
File metadata and controls
51 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import wx
import numpy as np
import math
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
class LineShapeFrame(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title,style= wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER, size = (480,640))
self.fig = Figure((6,6),dpi=80)
panel = wx.Panel(self,-1)
sizer = wx.BoxSizer(wx.VERTICAL)
agg = FigureCanvasWxAgg(panel,-1,self.fig)
self.point_x = []
self.point_y = []
sizer.Add(agg,0,wx.TOP)
self.labelText = wx.StaticText(panel,-1,"You have not clicked! ")
sizer.Add(self.labelText,0,wx.Top)
panel.SetSizer(sizer)
agg.Bind(wx.EVT_LEFT_DOWN,self.onLeftClick)
self.clickcount = 0
self.draw_figure()
def onLeftClick(self,event):
x,y = event.GetPosition()
x,y = self.ax.transData.inverted().transform([x,y])
self.point_x.append(x)
self.point_y.append(-y)
print "you click (%d,%d)" % (x,y)
self.labelText.LabelText = "you click (%f,%f)" % (x,y)
self.clickcount = self.clickcount + 1
self.draw_figure()
def draw_figure(self):
print("hello")
self.fig.clf()
x = np.linspace(0,1,480)
y = np.sin(x * 2 * 3.14 * (8 + self.clickcount)) * x * (x + 0.5)
self.ax = self.fig.add_subplot(111)
self.ax.plot(x,y)
xarray = np.array(self.point_x)
yarray = np.array(self.point_y)
self.ax.plot(xarray,yarray,'go')
self.fig.canvas.draw()
app = wx.App()
top = LineShapeFrame(None,-1,'LineFrame')
top.Show()
app.MainLoop()