"python/smc/multiprocessing/networking/client.py" did not exist on "5e8584b0d15a1b1dbe05b159b842fb6bafa77a6b"
Select Git revision
ACM-Reference-Format.bst
draw_path.py 1.13 KiB
import numpy as np
import matplotlib.pyplot as plt
# used for drawing
# it's hacked from lasso where there's drawing
from matplotlib.path import Path
from matplotlib.widgets import LassoSelector
class DrawPath:
def __init__(self, ax):
self.canvas = ax.figure.canvas
self.lasso = LassoSelector(ax, onselect=self.onselect)
def onselect(self, verts):
# verts is a list of tuples
self.path = np.array( [ [i[0], i[1]] for i in verts ] )
#self.canvas.draw_idle()
def disconnect(self):
self.lasso.disconnect_events()
self.canvas.draw_idle()
if __name__ == '__main__':
subplot_kw = dict(xlim=(0, 1), ylim=(0, 1), autoscale_on=False)
fig, ax = plt.subplots(subplot_kw=subplot_kw)
selector = DrawPath(ax)
def accept(event):
if event.key == "enter":
print("path points:")
print(selector.path)
selector.disconnect()
ax.set_title("")
print("TODO: run clik on me")
exit()
fig.canvas.mpl_connect("key_press_event", accept)
ax.set_title("Press 'Enter' to accept drawn path.")
plt.show()