2013-01-24 14 views
7

我作出這樣的一些補丁等等 -爲什麼matplotlib.PatchCollection與修補程序的顏色混淆?

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.plotAxes.add_artist(node.shape) 
self.plotAxes.add_artist(node.brushShape) 

這工作得很好。但是現在我想將它們放入PatchCollection並將該PatchCollection放到軸上。但是,當我這樣做時,我所有的形狀都只是藍色。我不明白怎麼把一個集合變成某種顏色。任何人都可以幫我解決我需要做什麼來保持我輸入的顏色值作爲補丁的faceColor?

新代碼 -

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) 

回答

13
self.p = PatchCollection(self.patches, match_original=True) 

默認情況下補丁集合過度乘坐的是能夠將顏色映射,週期顏色等,這目的,給定的顏色(doc)是一個collection關卡功能(以及散佈圖背後代碼的功能)。

+0

這工作!非常感謝! – Sterling

+0

@pceccon謝謝您收到拼寫錯誤。我修好了,抱歉編輯被拒絕了。 – tacaswell