Skip to content
Snippets Groups Projects
Select Git revision
  • 3ee06d856e7b4b4e20ef3ee2aaa4cd4a2e8a13cf
  • main default protected
  • rosification
  • refactoring
  • pp
  • mpc
  • realtimelogplotter
  • alv
  • gitlab_ci_podman
  • restructuring
  • viz_fix
11 results

crocoddyl_ocp_clik.py

Blame
  • 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()