title: How to convert binary matplotlib to binary numpy array?
body: <p>I'm trying to plot x and y list then convert it to numpy array but with 0 and 255 value only, black and white.</p>
  <p>So i tried <a href="https://stackoverflow.com/questions/7821518/matplotlib-save-plot-to-numpy-array#answer-7821917">this</a> , it's working but i got an array with intermediary colors:</p>
  <pre><code>print(np.unique(data))
  [0 1 2 3 4 5 6 7 8 9 10 11 ... 255]
  </code></pre>
  <p>So my solution for now is:</p>
  <pre><code>import numpy as np
  import cv2
  import matplotlib.pyplot as plt
  from matplotlib.colors import ListedColormap
  
  input_file = &quot;image.png&quot;
  fig = plt.figure()
  
  # drawn points
  x = [1,2,3,4]
  y = [1,2,3,4]
  
  plt.axis('off')
  plt.plot(x, y, color='black', linewidth=1)
  plt.savefig(f&quot;{input_file}.IMG.png&quot;, dpi=100)
  
  def plot2Grayscale(image):
      im = cv2.imread(image) 
      gray= cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
      cmap = ListedColormap(['black', 'white'])
      plt.imsave(image, gray, cmap = cmap)        
      gray = cv2.imread(image, 0)
      return gray
  
  data = plot2Grayscale(f&quot;{input_file}.IMG.png&quot;)
  print(np.unique(data))
  
  </code></pre>
  <pre><code>[0 255]
  </code></pre>
  <p>What i'm asking is there is a way to got the binary array from plot without having to save it then read it like i did?</p>