Angus McMorland wrote: > Hi all, > > I'm trying to plot a colour bar for a scatter plot, and set the > maximum value of the plot to something arbitrary. At the moment it > always comes up as 255. How can I change this? > > ax = plt.gca() > pts = ax.scatter(coords[:,0], coords[:,1], c=np.linspace(0,1,n_pts), s=16, > edgecolors='k', linewidth=1) > > Also, there seem to be many different ways to make colorbars associate > with certain objects like the colorbar keyword to scatter perhaps, but > the simplest/only way to create a colorbar that I can get to work is: > > ax.figure.colorbar(ax.images[0]) > > Is there a better way to do this so the vmin and vmax attributes of > the scatter plot get used in the colorbar? > > Thanks, > > Angus.
Maybe I am misunderstanding you, but the ipython -pylab approach looks like this: In [1]:x = rand(20) In [2]:y = rand(20) In [3]:z = rand(20)*10 In [4]:scatter? In [5]:sc = scatter(x, y, c=z) In [6]:sc Out[6]:<matplotlib.collections.RegularPolyCollection object at 0x8d8dd6c> In [7]:colorbar? In [8]:colorbar(sc) Out[8]:<matplotlib.colorbar.Colorbar instance at 0x92d29cc> The more object-oriented approach with ax.scatter, etc. is essentially the same. If color mapping is used by scatter, then the collection it returns is a "mappable", which is the argument colorbar needs to make the connection. Eric ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users