circle collection get_facecolors in Basemap

Hello,

I'm trying to plot text objects with the color used in m.scatter. My goal is
to individually label each scatter object. I've tried the following:

circles=m.scatter(cx,cy,zsize,zlevel,cmap=cmap)

and then:
CC = circles.get_facecolor()
i=0
for x,y in map(cx,cy):
    ax.text(x,y,'some text', color=CC[i])

But if fails because:

m.scatter returns:
<matplotlib.collections.CircleCollection object at 0x127898d0>

Rather than a list of objects??? Or something. The point is, I would expect
'circles' above to have len==cx, but it does not. What am I doing wrong?

···

--
View this message in context: http://www.nabble.com/circle-collection-get_facecolors-in-Basemap-tp25530811p25530811.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

John [H2O] wrote:

Hello,

I'm trying to plot text objects with the color used in m.scatter. My goal is
to individually label each scatter object. I've tried the following:

circles=m.scatter(cx,cy,zsize,zlevel,cmap=cmap)

and then:
CC = circles.get_facecolor()
i=0
for x,y in map(cx,cy):
    ax.text(x,y,'some text', color=CC[i])

But if fails because:

m.scatter returns:
<matplotlib.collections.CircleCollection object at 0x127898d0>

Rather than a list of objects??? Or something. The point is, I would expect
'circles' above to have len==cx, but it does not. What am I doing wrong?

The first thing you are doing wrong is failing to provide a complete, minimal, self-contained example illustrating the problem. I don't think the snippet you gave is representative of what you are running. Instead of "map" I think you mean "zip". Where are you incrementing "i"?

The general approach of using the get_facecolor() method to get the array, and indexing into it, is fine. That is not where the problem is. Once you put together a minimal example, I think you will find the problem--or that there really is no problem.

A collection is used by scatter because it is much more efficient than a sequence of objects.

Eric

···