title: pyQt5 matplotlib on key press image slices
body: <p>Matplotlib does not respond to key presses while embedded in PyQt5. I have verified that key presses work with Tkinter. This is my first PyQt5 experience. I am not sure what I'm doing wrong here. I have tried to set the focus on canvas by doing. All this is to display 3D volumetric data, which you can think of as a stack of images. Together, they describe a 3D structure. For example, magnetic resonance imaging (MRI) </p>
  
  <pre><code>self.canvas.setFocusPolicy( QtCore.Qt.ClickFocus )
  self.canvas.setFocus()
  </code></pre>
  
  <p>however that returns an error:</p>
  
  <pre><code>self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
  AttributeError: 'InputCanvas' object has no attribute 'canvas'
  </code></pre>
  
  <p>This is the code I have:</p>
  
  <pre><code>import sys
  from PyQt5 import QtCore
  from skimage import io
  from PyQt5.QtWidgets import QMainWindow, QSizePolicy
  from matplotlib.figure import Figure
  import matplotlib.pyplot as plt
  from PyQt5.QtWidgets import QApplication
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as 
  FigureCanvas
  
  
  class App(QMainWindow):
  
  def __init__(self):
      super().__init__()
      self.left = 10
      self.top = 10
      self.title = 'PYQT'
      self.width = 600
      self.height = 400
      self.initialize_ui()
  
  def initialize_ui(self):
      self.setWindowTitle(self.title)
      self.setGeometry(self.left, self.top, self.width, self.height)
      m = InputCanvas(self, width=3, height=3)
      m.move(200, 20)
      self.show()
  
  
  class InputCanvas(FigureCanvas):
  
      def __init__(self, parent=None, width=5, height=4, dpi=100):
          fig = Figure(figsize=(width, height), dpi=dpi)
  
          FigureCanvas.__init__(self, fig)
          self.setParent(parent)
          FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
          FigureCanvas.updateGeometry(self)
          self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
          self.canvas.setFocus()
          fig.canvas.mpl_connect('key_press_event', self.process_key)
          self.input_plot()
  
      def input_plot(self):
          volume = io.imread("14.mha", plugin='simpleitk')
          ax = self.figure.add_subplot(111)
          ax.volume = volume
          ax.index = volume.shape[0] // 2
          ax.set_title('Ground Truth Image')
          plt.set_cmap("gray")
          plt.axis('off')
          ax.imshow(volume[ax.index])
          self.draw()
  
      def process_key(self, event):
          fig = event.canvas.figure
          ax = fig.axes[0]
          if event.key == 'j':
              self.previous_slice(ax)
          elif event.key == 'k':
              self.ext_slice(ax)
          self.draw()
  
      def previous_slice(self, ax):
          volume = ax.volume
          ax.index = (ax.index - 1) % volume.shape[0]  # wrap around using %
          ax.images[0].set_array(volume[ax.index])
  
      def next_slice(self, ax):
          volume = ax.volume
          ax.index = (ax.index + 1) % volume.shape[0]
          ax.images[0].set_array(volume[ax.index])
  
  
  if __name__ == '__main__':
     app = QApplication(sys.argv)
     ex = App()
     sys.exit(app.exec_())
  </code></pre>