How to update imshow in matplotlib without overwriting new color bar or subplot title?
Question: **Background:** I am working an a data processing application and am trying to
visualize 2D arrays with matplotlib embedded into a tkinter gui. I am trying
to update the matplotlib figure by collecting user input (i.e. what frame they
want displayed, various other options) so I do not want to generate the
animation in advance.

**System:** Windows xp, Python 2.7, matplotlib 1.1.1rc

**Question:** How do I update only the image produced by imshow and not the
colorbar?

**GUI** ![gui snapshot](http://i.stack.imgur.com/CIXjL.png) _Notice how color
bars write over themselves._

**Code:** _note: the code below is untested, however it is the basic idea of
how my current code is setup_

    
    
    import matplotlib
    import matplotlib.pyplot as plt
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    import Tkinter as tk
    import numpy as np
    
    
    class MainWindow:
        def __init__(self,application):
            self.mainframe=tk.Frame(application)
    
            #update button
            ttk.Button(application,text='Update',command=self.update).pack()
    
            #matplotlib setup
            self.ren2DFig=plt.figure(figsize=(4,4),dpi=100)
            self.renCanvas=FigureCanvasTkAgg(self.ren2DFig,master=self.renWin2D)
            self.renCanvas.show()
            self.renCanvas.get_tk_widget().pack()
    
            self.subPlot=self.ren2DFig.add_subplot(111)
            self.subPlot.get_yaxis().set_visible(False)
            self.subPlot.get_xaxis().set_visible(False)
            self.subPlot.get_axes().set_frame_on(False)
            frame=np.zeros((20,40),)
            frame[9:11 ,9:11]=1
            frame[5 ,5]=.5
            self.im=self.subPlot.imshow(self.rotate(frame), origin = 'lower')
            self.cbar=self.ren2DFig.colorbar(self.im)
            self.cbar.set_label('Solid Fraction')
            self.renCanvas.draw()
            self.ren2DFig.canvas
    
        def update(self):
            self.im.set_array(np.zeros((20,40),))
            self.renCanvas.draw() # I think this is the problem?
    
    application=tk.Tk()
    application.focus_force()
    window=MainWindow(application)
    application.protocol("WM_DELETE_WINDOW",window.close)
    application.mainloop()
    

Any help would be much appreciated! Thanks!

**Update**[July 13, 2012]:

If I try clearing the subplot, then adding the image and color bar back,
finally re-drawing the canvas I get this:

![matplotlib](http://i.stack.imgur.com/9rqby.png)

What the heck am I doing wrong?????? This is really starting to irritate me.


Answer: I figure it out. The problem is with

    
    
    self.subPlot.get_axes().set_frame_on(False)
    

I guess it is a bug or something but if I change it to True, i.e.

    
    
    self.subPlot.get_axes().set_frame_on(True)
    

It works just fine, everything updates like normal.

This little thing stumped me for two days!!! Go figure. lol.

