title: How to plot binary data in python?
body: <p>First of all I know my question is frequently asked. But I have not found a solution in them.</p>
  
  <p>I work with USBTMC to control oscilloscope. <a href="https://www.mankier.com/1/pythonusbtmc" rel="nofollow noreferrer">Here</a> you can find more information about it. I am able to capture screen and write it into a file (see picture). But I want to plot screen every <code>n</code> secs in real time. I would like to use <code>matplotlib.pyplot</code>, for example. </p>
  
  <p><a href="https://i.stack.imgur.com/5Be3X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Be3X.png" alt="enter image description here"></a></p>
  
  <p>Here is my code (with a desperate attempt to plot data with <code>pyplot</code>):</p>
  
  <pre><code>import usbtmc
  from time import sleep 
  import matplotlib.pyplot as plot
  import numpy as np
  import subprocess
  
  maxTries = 3
  
  scope = usbtmc.Instrument(0x0699, 0x03a6)
  print scope.ask("*IDN?")
  
  scope.write("ACQ:STOPA SEQ")
  scope.write("ACQ:STATE ON")
  
  while ( True ):
    #get trigger state  
    trigState = scope.ask("TRIG:STATE?")
    #check if Acq complete 
    if ( trigState.endswith('SAVE') ):
      print 'Acquisition complete. Writing into file ...'
      #save screen
      scope.write("SAVE:IMAG:FILEF PNG")
      scope.write("HARDCOPY START")
  
      #HERE I get binary data
      screenData = scope.read_raw()
  
      #HERE I try to convert it?
      strData = np.fromstring( screenData, dtype=np.uint8 )
  
      #HERE I try to plot previous
      plot.plot( strData )
      plot.show()
  
      #rewrite in file (this works fine) 
      try:
        outFile = open("screen.png", "wb")
        outFile.write( screenData )
      except IOError:
        print 'Error: cannot write to file'
      else:
        print 'Data was written successfully in file: ', outFile.name
      finally:
        outFile.close()
   #continue doing something
  </code></pre>
  
  <p>After run this code I get ... look at the picture.
  <a href="https://i.stack.imgur.com/JURel.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JURel.png" alt="enter image description here"></a></p>