Skip to content
Snippets Groups Projects
Commit 38aaa3f0 authored by m-guberina's avatar m-guberina
Browse files

added path drawing

parent 4289c04e
Branches
No related tags found
No related merge requests found
No preview for this file type
File added
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment