|
From: Ryan M. <rm...@gm...> - 2008-12-08 18:55:56
|
Chad Kidder wrote:
> I've got many series of data that I want to plot, and each has an
> additional scalar that is valid for the whole series. What I want to
> do is plot all these series on top of each other (plot can do this
> just fine), but with the additional scalar changing the color,
> efectively using color as the z-axis. I'm not seeing how to do that.
> If there was a function where I could give a color map a value and it
> would spit out the color, that would work, but I haven't seen it.
> Thanks for your help.
Try using scatter instead of plot. Specifically, the 'c' keyword argument:
*c*:
a color. *c* can be a single color format string, or a
sequence of color specifications of length *N*, or a
sequence of *N* numbers to be mapped to colors using the
*cmap* and *norm* specified via kwargs (see below). Note
that *c* should not be a single numeric RGB or RGBA
sequence because that is indistinguishable from an array
of values to be colormapped. *c* can be a 2-D array in
which the rows are RGB or RGBA, however.
For example:
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(100)
y = np.random.randn(100)
data = x**2 + y**2
plt.scatter(x, y, c=data)
plt.show()
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
|