Continuously varying line colors?

I'm hoping to generate a line plot where the color of each pixel on
the plot is given by linearly interpolating the colormap from each
point specified in the line, instead of having the whole line be a
solid color. I can "mock this up" by doing a scatter plot where the
points are much closer together than the screen resolution, but that
seems inelegant, and sometimes produces weird output. So is there a
way to do effectively the same thing with a line plot or somehow
specify this behavior in scatter?

Hi Erik,

···

On Mon, May 4, 2009 at 09:22, Erik Tollerud <erik.tollerud@...287...> wrote:

I'm hoping to generate a line plot where the color of each pixel on
the plot is given by linearly interpolating the colormap from each
point specified in the line, instead of having the whole line be a
solid color. I can "mock this up" by doing a scatter plot where the
points are much closer together than the screen resolution, but that
seems inelegant, and sometimes produces weird output. So is there a
way to do effectively the same thing with a line plot or somehow
specify this behavior in scatter?

maybe this[1] could be of help?

[1] http://www.scipy.org/Cookbook/Matplotlib/MulticoloredLine

Cheers,
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

IIRC, the backends that matplotlib uses (Gtk, Agg, etc.) only support a single color per line, so breaking up the line into different segments/points is really your only option. Instead of scatter, you can break up your line into separate sections and have them colormapped for you, using a LineCollection.

Ryan

···

On Mon, May 4, 2009 at 2:22 AM, Erik Tollerud <erik.tollerud@…287…> wrote:

I’m hoping to generate a line plot where the color of each pixel on

the plot is given by linearly interpolating the colormap from each

point specified in the line, instead of having the whole line be a

solid color. I can “mock this up” by doing a scatter plot where the

points are much closer together than the screen resolution, but that

seems inelegant, and sometimes produces weird output. So is there a

way to do effectively the same thing with a line plot or somehow

specify this behavior in scatter?


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

Ah, I see... well, that's doable although not necessarily ideal.
Thanks to you both!

···

On Mon, May 4, 2009 at 10:24 AM, Ryan May <rmay31@...287...> wrote:

On Mon, May 4, 2009 at 2:22 AM, Erik Tollerud <erik.tollerud@...287...> > wrote:

I'm hoping to generate a line plot where the color of each pixel on
the plot is given by linearly interpolating the colormap from each
point specified in the line, instead of having the whole line be a
solid color. I can "mock this up" by doing a scatter plot where the
points are much closer together than the screen resolution, but that
seems inelegant, and sometimes produces weird output. So is there a
way to do effectively the same thing with a line plot or somehow
specify this behavior in scatter?

IIRC, the backends that matplotlib uses (Gtk, Agg, etc.) only support a
single color per line, so breaking up the line into different
segments/points is really your only option. Instead of scatter, you can
break up your line into separate sections and have them colormapped for you,
using a LineCollection.

Ryan

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

--
Erik Tollerud
Graduate Student
Center For Cosmology
Department of Physics and Astronomy
2142 Frederick Reines Hall
University of California, Irvine
Office Phone: (949)824-2587
Cell: (651)307-9409
etolleru@...2143...