Why is matplotlib.PatchCollection messing with col

2019-02-21 21:53发布

I make a number of patches like so -

node.shape = RegularPolygon((node.posX, node.posY),
                            6,
                radius = node.radius,
                                    edgecolor = 'none',
                                    facecolor = node.fillColor,
                                    zorder = node.zorder)

node.brushShape = RegularPolygon((node.posX, node.posY),
                            6,
                node.radius * 0.8,
                linewidth = 3,
                                    edgecolor = (1,1,1),
                                    facecolor = 'none',
                                    zorder = node.zorder)

And originally I was just putting them straight onto my axis like this -

self.plotAxes.add_artist(node.shape)
self.plotAxes.add_artist(node.brushShape)

That worked fine. But now I want to put them into a PatchCollection and put that PatchCollection onto the axis. However, when I do that, all of my shapes are just blue. I don't understand how just putting into a collection is changing the color somehow. Can anyone help me out on what I need to be doing to keep the color values that I input as the faceColor for the patches?

The new code is -

node.shape = RegularPolygon((node.posX, node.posY),
                        6,
            radius = node.radius,
                                edgecolor = 'none',
                                facecolor = node.fillColor,
                                zorder = node.zorder)

node.brushShape = RegularPolygon((node.posX, node.posY),
                        6,
            node.radius * 0.8,
            linewidth = 3,
                                edgecolor = (1,1,1),
                                facecolor = 'none',
                                zorder = node.zorder)

self.patches.append(node.shape)
self.patches.append(node.brushShape)


self.p = PatchCollection(self.patches) 
self.plotAxes.add_collection(self.p) 

1条回答
爷、活的狠高调
2楼-- · 2019-02-21 22:10
self.p = PatchCollection(self.patches, match_original=True) 

By default patch collection over-rides the given color (doc) for the purposes of being able to apply a color map, cycle colors, etc. This is a collection level feature (and what powers the code behind scatter plot).

查看更多
登录 后发表回答