title: QT draw a gray image into pseudo color (PyQt)
body: <p>Currently, I have a image (numpy), and I want to draw it in QLabel with color. </p>
  
  <p>A similar demo can be find: <a href="https://matplotlib.org/users/image_tutorial.html" rel="nofollow noreferrer">https://matplotlib.org/users/image_tutorial.html</a>. The matplotlib can display the image using imshow with a colormap. </p>
  
  <p>Now, I can display the gray image in QLabel, but I do not know how to display it as a pseudo color. </p>
  
  <p>The code used to display the gray image is (the self.img is what I have):</p>
  
  <pre><code>import sys
  from PyQt5.QtCore import *
  from PyQt5.QtGui import *
  from PyQt5.QtWidgets import *
  import numpy as np
  import qimage2ndarray
  class MyLabel(QLabel):
      def __init__(self):
          super(MyLabel, self).__init__()
          img = np.zeros((256,256))
          img[0:128,0:128] = 255
          self.img = img
  
      def paintEvent(self, QPaintEvent):
          super(MyLabel, self).paintEvent(QPaintEvent)
  
          QImg = qimage2ndarray.gray2qimage(self.img)
  
          pos = QPoint(0, 0)
          source = QRect(0, 0, 256,256)
  
          painter = QPainter(self)
          painter.drawPixmap(pos, QPixmap.fromImage(QImg), source)
  
  class Window(QWidget):
      def __init__(self):
          super(Window, self).__init__()
          layout = QHBoxLayout(self)
          self.label = MyLabel()
          layout.addWidget(self.label)
  
  
  if __name__ == '__main__':
  
      app = QApplication(sys.argv)
      window = Window()
      window.show()
      sys.exit(app.exec_())
  </code></pre>