Just curious if you're interested in folks contributing to the gallery. I was playing around trying to come up with a routine to automatically choose colors when plotting several datasets, not necessarily from a single array, but rather say iterating through a list of datasets. I came up with the following... maybe it's of interest? And certainly of interest to me... any advice on what could be done better!
Thanks! > #!/usr/bin/env python > > import numpy as np > import matplotlib.pyplot as plt > import matplotlib.cm as cm > import matplotlib.colors as colors > > """A script to demonstrate automatically assigning colors based > on the number of x,y pairs to be plotted. """ > > # First example > # set up some example data > x = np.random.random((430,23)) > > # This is the important part for 'autocoloring' > # get an array of 0-1 values, length of numint (#data sets > # that you will iterate through), these will define the colors > numint = x.shape[1] > Nc = np.array([float(i)/numint for i in range(numint)]) > norm = colors.normalize(Nc.min(),Nc.max()) > > fig = plt.figure() > ax = fig.add_subplot(111) > interval = 0 > for i in range(numint): > #get a new color > cmap = cm.jet(norm(Nc[i])) > ax.scatter(x[:,0],x[:,i],color=cmap) > > > # Second example > # something a little more interesting > fig2 = plt.figure() > ax2 = fig2.add_subplot(111) > X = np.arange(400) > y = np.sin(X) > y2 = X*.2 > x = np.column_stack((y,y2)) > > #define an interval, the dataset is divided by this value > intervalsize = 23 > numint = int(np.round(x.shape[0]/intervalsize)) + 1 > > # This is the important part for 'autocoloring' > # get an array of 0-1 values, length of numint > # these will define the colors > Nc = np.array([float(i)/numint for i in range(numint)]) > norm = colors.normalize(Nc.min(),Nc.max()) > > interval = 0 > for i in range(0,len(x),intervalsize): > # define the index array (easier than typing) > indx = np.arange(i,i+intervalsize) > #get a new color > cmap = cm.jet(norm(Nc[interval])) > # the indx as defined above may exceed > # the data array > try: > ax2.scatter(x[indx,0],x[indx,1],color=cmap) > #print indx > # case to handle tail of data > except: > #plt.scatter(x[i:,0],x[i:,1],color=cmap) > print 'OOPS, index exceeds dimensions:',indx > pass > # so that you don't miss the last interval > if len(x)-i < intervalsize: > ax2.scatter(x[i+1:,0],x[i+1:,1],color=cmap) > print 'last bits...' > interval+=1 > > plt.show() > -- View this message in context: http://www.nabble.com/contribute-to-gallery--Or%2C-just-advice-on-changing-colors-automagically....-tp24419101p24419101.html Sent from the matplotlib - users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users