Adding Colorbar and Contour Map to PyPlot surface imshow in Python
Question: I am using code written by a former employee. In this code, the person
performs a plot on Python using Qt. I'm trying to add a colorbar and contour
maps, but to no avail. Here's part of the code that's relevant.

    
    
    #IMPORTS
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
    
    #SETUP
    fig = Figure()
    axes = fig.add_subplot(111)
    canvas = FigureCanvas(fig)
    
    #DRAWING
    axes.clear()
    axes.imshow(data_and_extents, interpolation='bilinear')
    axes.autoscale(False)
    canvas.draw()
    
    #TODO: Add colorbar and contour maps with some values
    

I have tried axes.colorbar() to no avail. How do I add colorbars and contour
maps to surface plots set up like this?

Thanks SOCommunity!


Answer: The first error is in the first line:

    
    
    from matplotlib.figure import Figure
    

is the correct one. Next: Instead of `axes.colorbar` it's `fig.corbar`. With
your variable names you should be able to create a colorbar with:

    
    
    cbar = fig.colorbar(axes)
    

See [this
example](http://matplotlib.sourceforge.net/examples/pylab_examples/colorbar_tick_labelling_demo.html)
for more.

