forked from frederiklyngsoee/portfolioIDS2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphController.py
More file actions
19 lines (13 loc) · 765 Bytes
/
GraphController.py
File metadata and controls
19 lines (13 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor, Button
class GraphController:
def __init__(self): #Constructor
self.p, = plt.plot(0,0,'o') #Plot origin
self.cursor = Cursor(self.ax, horizOn=True, vertOn = True, color = 'red', linewidth = 2.0) ##Cursor coordinates + crosshair
self.coords = [] ##Init coord-array
self.cid = self.fig.canvas.mpl_connect('button_press_event', self.onclick) #Make connection between mouse and screen
def update(self): #Updates the plot
plt.show()
def onclick(self,event): #Onclick event that adds a vertex to the array and plots it aswell.
self.coords.append([event.xdata, event.ydata])
self.ax.plot(event.xdata,event.ydata,'o')