Paul Hobson, on 2012-01-28 23:21, wrote: > There is undoubtedly a more efficient way to do this, but give this a shot: > > import numpy as np > import matplotlib.pyplot as plt > > x = np.arange(0, 10.5, 0.5) > y = -3.0*x + 0.5*x**2 > > color_list = ['FireBrick', 'Orange', 'DarkGreen', 'DarkBlue', 'Indigo'] > limits = np.arange(0, 11, 2) > fig, ax1 = plt.subplots() > for n, color in enumerate(color_list): > lower = np.where(x >= limits[n])[0] > upper = np.where(x <= limits[n+1])[0] > index = np.intersect1d(lower, upper) > ax1.plot(x[index], y[index], linestyle='-', color=color, linewidth=2)
Another way (if you're ok with only coloring the markers) would be to use ax1.scatter(x,y,c=colorlist) where the length of all three arguments is the same. Scatter can do that with the size of the markers by passing the s= argument. best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users