
plots = None
def plot_hist(data):
    global plots    
    (h,x) = histogram(data)     #(h,x) = histogram(data, 0, 255) is more efficient: no neet to calculate min & max
    if plots is None:
        plots = plot(h, xdata = x, title = "Histo")
    else:
       plots[0].getSeries(0).setData(x,h)

while(True):
    data = img.getData().getRectSelection(0,0,500,250)
    plot_hist(data)
    if plots[0].displayable == False: 
        break
    time.sleep(0.250)
