Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

python - Why is matplotlib.PatchCollection messing with color of the patches?

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) 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...