on click pause the real time plot of data
<p>I simply want to put a pause clause to my plot where I can pause the real time stream voluntarily. 
This is what I am trying. This is an edited code. It s making two subplots: scatter and pie chart. I am able to pause the scatter plot but when I pause pie chart disappears.</p>

<pre><code>def onClick(event):
    global pause
    pause ^= True
fig = plt.figure()
fig.canvas.mpl_connect('button_press_event', onClick)
plt.show()

while t&lt;ran2:       
      if not pause:
         ax = fig.add_subplot(2,1,1)
         ay = fig.add_subplot(2,1,2)
         mdfmt = md.DateFormatter('%H:%M')
         ax.xaxis.set_major_formatter(mdfmt)
         cmap=cm.jet
         g=s[t:t+4]
         h=[]
         for i in g:
             if i == 'Match':
                 h.append(1)
             else:
                 h.append(0)
         ax.scatter(x[t:t+4],y[t:t+4],c=h,s=150,marker='&lt;',edgecolor='None', cmap = cm.jet)
         ax.set_xlabel('Time')
         ax.set_ylabel('Action')
         mindate = min(data_mat['Date'].ix[t:t+4])
         ax.set_title('Alarm System for site SPFD02 on date %s'%mindate)
         yt=[-1,0,1]
         ax.set_yticks(yt)
         ax.set_yticklabels(('Closed','Not Ack','Assigned'))
         ax.set_xlim(x[t],x[t+4])    

# for pie chart
         l = 'Match','No-Match'
         colors = ['red','blue']
         j = s[t:t+4].count('Match')
         z = z + j
         k = s[t:t+4].count('No-Match')
         r = r + k
         sizes = [z,r]
         ay.pie(sizes,labels = l, colors = colors, autopct='%1.1f%%', shadow=True, startangle=140)
         ay.set_aspect('equal')        
         t=t+1
   else:
        print 'paused'
plt.pause(0.1)
plt.cla() 
</code></pre>