class_docstr: A polygon editor.
  
  Key-bindings
  
    't' toggle vertex markers on and off.  When vertex markers are on,
        you can move them, delete them
  
    'd' delete the vertex under point
  
    'i' insert a vertex at point.  You must be within epsilon of the
        line connecting two existing vertices
class_docstr_tok: ["A","polygon","editor",".","Key-bindings","'t","'","toggle","vertex","markers","on","and","off",".","When","vertex","markers","are","on",",","you","can","move","them",",","delete","them","'d","'","delete","the","vertex","under","point","'","i","'","insert","a","vertex","at","point",".","You","must","be","within","epsilon","of","the","line","connecting","two","existing","vertices"]
docstr: Callback for key presses.
docstr_tok: ["Callback","for","key","presses","."]
code: def on_key_press(self, event):
      """Callback for key presses."""
      if not event.inaxes:
          return
      if event.key == "t":
          self.showverts = not self.showverts
          self.line.set_visible(self.showverts)
          if not self.showverts:
              self._ind = None
      elif event.key == "d":
          ind = self.get_ind_under_point(event)
          if ind is not None:
              self.poly.xy = np.delete(self.poly.xy, ind, axis=0)
              self.line.set_data(zip(*self.poly.xy))
      elif event.key == "i":
          xys = self.poly.get_transform().transform(self.poly.xy)
          p = event.x, event.y  # display coords
          for i in range(len(xys) - 1):
              s0 = xys[i]
              s1 = xys[i + 1]
              d = dist_point_to_segment(p, s0, s1)
              if d <= self.epsilon:
                  self.poly.xy = np.insert(
                      self.poly.xy,
                      i + 1,
                      [event.xdata, event.ydata],
                      axis=0,
                  )
                  self.line.set_data(zip(*self.poly.xy))
                  break
      if self.line.stale:
          self.canvas.draw_idle()
  
file_path: matplotlib/galleries/examples/event_handling/poly_editor.py
imports: import numpy
  from matplotlib.artist import Artist
  from matplotlib.lines import Line2D
label_desc: Use image node_id 7 for calling the PolygonInteractor obj's underlying member method code with example usage: obj.on_key_press(event) without return types