Hi All,
I was wondering how I take a list of 250 discrete values and match up each value in the list to a color in the gist_rainbow colormap. I want the highest value to be red, and the lowest value to be blue. I then want to plot a point for each value in the list, and the point’s color should represent its value. I cannot use contourf or any other function that does this automatically on a continuous grid–I need to plot individual points.
I have tried creating my own colormap with:
my_colors = matplotlib.colors.Colormap(my_list)
but when I issue a pyplot.plot() command with the argument cmap=my_colors, I get "TypeError: There is no patch property “cmap”
How do I do this correctly?
Cheers,
Katie
I think you are looking for "scatter", with the "c" argument being
your intensity value. You can pass the gist_rainbow colormap to the
scatter function via the cmap argument. See these examples
http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo.html
http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo2.html
···
On Mon, Sep 26, 2011 at 12:05 PM, Katie Boyle <katielboyle@...287...> wrote:
Hi All,
I was wondering how I take a list of 250 discrete values and match up each
value in the list to a color in the gist_rainbow colormap. I want the
highest value to be red, and the lowest value to be blue. I then want to
plot a point for each value in the list, and the point's color should
represent its value. I cannot use contourf or any other function that does
this automatically on a continuous grid--I need to plot individual points.
Eg,
In [43]: x, y, c = np.random.randn(3, 100)
In [44]: plt.scatter(x, y, c=c, cmap='gist_rainbow')
Out[44]: <matplotlib.collections.PathCollection object at 0x981b22c>
···
On Mon, Sep 26, 2011 at 12:24 PM, John Hunter <jdh2358@...287...> wrote:
On Mon, Sep 26, 2011 at 12:05 PM, Katie Boyle <katielboyle@...287...> wrote:
Hi All,
I was wondering how I take a list of 250 discrete values and match up each
value in the list to a color in the gist_rainbow colormap. I want the
highest value to be red, and the lowest value to be blue. I then want to
plot a point for each value in the list, and the point's color should
represent its value. I cannot use contourf or any other function that does
this automatically on a continuous grid--I need to plot individual points.
I think you are looking for "scatter", with the "c" argument being
your intensity value. You can pass the gist_rainbow colormap to the
scatter function via the cmap argument. See these examples
http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo.html
http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo2.html