为什么 matplotlib.PatchCollection 会弄乱补丁的颜色? [英] 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)
效果很好.但是现在我想将它们放入 PatchCollection 并将该 PatchCollection 放在轴上.然而,当我这样做时,我所有的形状都是蓝色的.我不明白只是放入一个集合是如何以某种方式改变颜色的.任何人都可以帮助我了解我需要做些什么来保持我输入的颜色值作为补丁的 faceColor 吗?
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?
新代码是 -
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)
推荐答案
self.p = PatchCollection(self.patches, match_original=True)
默认情况下,补丁集合会覆盖给定的颜色(doc) 以便能够应用颜色图、循环颜色等.这是一个 collection
级别的功能(以及散点图背后的代码的动力).
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).
这篇关于为什么 matplotlib.PatchCollection 会弄乱补丁的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!