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)

plt.show()

HTH,
-paul

On Fri, Jan 27, 2012 at 8:12 AM, nahren manuel <meetnah...@yahoo.com> wrote:
> Dear Users,
> I want to plot a XY, the X-value is constant, but let assume Y varees from
> 1-10, so I want o have different colors accordingly for the range
> 0-2,2-4,4-6,6-8,8-10.
>
> thanks a lot
> najren
>
> ------------------------------------------------------------------------------
> 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
>

------------------------------------------------------------------------------
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

Reply via email to