matplotlib.pyplot non-blocking plot becomes unresponsive
<p>I'm writing a script that will update a matplotlib plot continuously for a predetermined amount of time while allowing the rest of my code to run in the background. The code below "works" and causes the plot to update as desired for about 5 seconds and then the plot window becomes unresponsive. </p>

<p>The first block in my code prepares the plot figure for subsequent updates, and the """###SPECTRUM PLOT###""" block is where the update occurs.</p>

<p>Is my initial preparation following best practices? Is there a limit to how many times you can update/change the data in a plot or is there a memory limit within a plot? I've tried using plt.ion(), but it doesn't result in non-blocking behavior.</p>

<pre><code>#prepare plot window for periodic updates
plt.figure(selection)
plt.subplot(111, axisbg='k')
specPlot,  = plt.plot([], [], 'y')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Amplitude (dBm)')
plt.title('Spectrum')
plt.show(block=False) #required to update plot w/o stopping the script
plt.xlim(np.amin(freq), np.amax(freq))
plt.ylim(refLevel.value-100, refLevel.value)


"""#################ACQUIRE/PROCESS DATA#################"""
#start acquisition
spectrums = 0
rsa.DEVICE_Run()
start = time.clock()
while end - start &lt; acqTime:
    rsa.SPECTRUM_AcquireTrace()
    while ready.value == False:
        rsa.SPECTRUM_WaitForDataReady(timeoutMsec, byref(ready))
    ready.value = False
    rsa.SPECTRUM_GetTrace(c_int(0), specSet.traceLength, 
        byref(traceData), byref(outTracePoints))
    spectrums += 1


    """#################SPECTRUM PLOT#################"""

    #update spectrum trace
    specPlot.set_xdata(freq)
    specPlot.set_ydata(traceData)

    #calculate and annotate peak power and frequency
    peakPower = np.amax(traceData)
    peakPowerFreq = freq[np.argmax(traceData)]
    #print('Peak power in spectrum: %4.3f dBm @ %d Hz' % 
     #   (peakPower, peakPowerFreq))

    peakFreqLine = plt.axvline(x=peakPowerFreq)
    text_x = specSet.actualStartFreq + specSet.span/20
    peakPowerText = plt.text(text_x, peakPower, 
        'Peak power in spectrum: %4.3f dBm @ %5.4f MHz' % 
        (peakPower, peakPowerFreq/1e6), color='white')

    plt.draw()
    peakFreqLine.remove()
    peakPowerText.remove()
    end = time.clock()

#comment this out if you want the plot to stay until the script finishes
rsa.DEVICE_Stop()
plt.close()    
</code></pre>