 # Line changes color along its length

Hey all,

I think I know the answer here as “no” or something, but say I have a curve I want to plot and I want the color to change along the curve to denote the 3rd variable is there anyway to do this is matplotlib?

What I mean is take the simple plot

from pylab import *

plot(range(30), range(30, 60), lw=10)

and say that the 3rd variable is

inten = [val ** 2 for val in range(30)]

then can the line change color along its length according to a specified color table?

In IDL this is done by just giving a color array with the same length as the data then the line changes with the current colortable.

Thanks much,

Brian

···

Brian A. Larsen
Space Science and Applications
Group ISR-1
Los Alamos National Laboratory

PO Box 1663, MS-D466
Los Alamos, NM 87545
USA

Phone: 505-665-7691
Fax: 505-665-7395
email: balarsen@…3267…

Correspondence /
Technical data or Software Publicly Available

Try this:

http://matplotlib.sourceforge.net/examples/pylab_examples/multicolored_line.html

Ryan

···

On Tue, Sep 7, 2010 at 6:50 PM, Brian Larsen <balarsen@...652...> wrote:

Hey all,
I think I know the answer here as "no" or something, but say I have a curve
I want to plot and I want the color to change along the curve to denote the
3rd variable is there anyway to do this is matplotlib?
What I mean is take the simple plot
from pylab import *
plot(range(30), range(30, 60), lw=10)
and say that the 3rd variable is
inten = [val ** 2 for val in range(30)]
then can the line change color along its length according to a specified
color table?
In IDL this is done by just giving a color array with the same length as the
data then the line changes with the current colortable.

--
Ryan May
School of Meteorology
University of Oklahoma

Perfect thank you, no wonder I didnt find it, plt.gca().add_collection(lc) never found its way to my radar.

Cheers,

Brian

···

On Sep 7, 2010, at 7:58 PM, Ryan May wrote:

On Tue, Sep 7, 2010 at 6:50 PM, Brian Larsen <balarsen@…652…> wrote:

Hey all,
I think I know the answer here as “no” or something, but say I have a curve
I want to plot and I want the color to change along the curve to denote the
3rd variable is there anyway to do this is matplotlib?
What I mean is take the simple plot
from pylab import *
plot(range(30), range(30, 60), lw=10)
and say that the 3rd variable is
inten = [val ** 2 for val in range(30)]
then can the line change color along its length according to a specified
color table?
In IDL this is done by just giving a color array with the same length as the
data then the line changes with the current colortable.

Try this:

http://matplotlib.sourceforge.net/examples/pylab_examples/multicolored_line.html

Ryan

Ryan May
School of Meteorology
University of Oklahoma

Brian A. Larsen
Space Science and Applications
Group ISR-1
Los Alamos National Laboratory

PO Box 1663, MS-D466
Los Alamos, NM 87545
USA