Python scattered chart legend
Question: I'm plotting a scattered chart which look like this :

    
    
    from pylab import *
    
    n = 1024
    X = np.random.normal(0,1,n)
    Y = np.random.normal(0,1,n)
    T = np.arctan2(Y,X)
    
    axes([0.025,0.025,0.95,0.95])
    scatter(X,Y, s=75, c=T, alpha=.5)
    
    xlim(-1.5,1.5), xticks([])
    ylim(-1.5,1.5), yticks([])
    # savefig('../figures/scatter_ex.png',dpi=48)
    show()
    

![enter image description here](http://i.stack.imgur.com/UNhY5.png)

I would like to add a legend to explain the color scale :

Like yellow is 0 red is 10 etc...

I cannot find a way to do it , it works for imshow like this one :

    
    
    from pylab import *
    
    def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
    
    n = 10
    x = np.linspace(-3,3,3.5*n)
    y = np.linspace(-3,3,3.0*n)
    X,Y = np.meshgrid(x,y)
    Z = f(X,Y)
    
    axes([0.025,0.025,0.95,0.95])
    imshow(Z,interpolation='nearest', cmap='bone', origin='lower')
    colorbar(shrink=.92)
    
    xticks([]), yticks([])
    # savefig('../figures/imshow_ex.png', dpi=48)
    show()
    

![enter image description here](http://i.stack.imgur.com/k8NSS.png)

BUt I cannot find a way to add it on scattered charts.

DOes anyone already had to deal with this issue ?

Thanks for your help.


Answer: Change the last few lines to:

    
    
    >>> s = scatter(X,Y, s=75, c=T, alpha=.5)
    >>> colorbar(s)
    >>> show()
    

![enter image description here](http://i.stack.imgur.com/krN31.png)

