Python 如何使用Matploblib用户定义的颜色映射查找白色?

Python 如何使用Matploblib用户定义的颜色映射查找白色?,python,matplotlib,color-mapping,Python,Matplotlib,Color Mapping,我用这个构造函数创建了一堆规则多边形- node.brushShape = RegularPolygon((node.posX, node.posY), 6, node.radius * 0.8, linewidth = 3, edgecolor = (1,1

我用这个构造函数创建了一堆规则多边形-

        node.brushShape = RegularPolygon((node.posX, node.posY),
                            6,
                            node.radius * 0.8,
                            linewidth = 3,
                            edgecolor = (1,1,1),
                            facecolor = 'none',
                            zorder = brushz)
node.brushShape = RegularPolygon((node.posX, node.posY),
                        6,
                        node.radius * 0.8,
                        linewidth = 3,
                        edgecolor = (1,1,1),
                        facecolor = 'none',
                        zorder = brushz)
正如你所看到的,我希望这些补丁的边缘是白色的。我把它们都放到一个名为brushShapes的列表中,然后创建一个PatchCollection-

self.brushShapesPC = PatchCollection(self.brushShapes, match_original=True)
这种方法可以很好地保持边缘的白色。但是,现在我想使用用户定义的颜色映射-

colormap = {'red':  ((0.0, 0.0, 0.0),
               (0.25,0.0, 0.0),
               (0.5, 0.8, 1.0),
               (0.75,1.0, 1.0),
               (1.0, 0.4, 1.0)),

        'green': ((0.0, 0.0, 0.0),
               (0.25,0.0, 0.0),
               (0.5, 0.9, 0.9),
               (0.75,0.0, 0.0),
               (1.0, 0.0, 0.0)),

        'blue':  ((0.0, 0.0, 0.4),
               (0.25,1.0, 1.0),
               (0.5, 1.0, 0.8),
               (0.75,0.0, 0.0),
               (1.0, 0.0, 0.0))} 
现在我的PatchCollection实例化是-

self.brushShapesPC = PatchCollection(self.brushShapes, cmap=mpl.colors.LinearSegmentedColormap('SOMcolormap', self.colormap))
但是现在边缘的颜色与脸的颜色相同!所以我需要做的是-用新的颜色映射确定白色的值..并更改

edgecolor = (1,1,1)

在本构装师中—

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

是这样吗?我一直在努力确定白色的值是多少。当我打开一个色条时,它显示白色在中间…所以我尝试了(0.5,0.5,0.5),(0,1,0)等等。有人能帮我弄清楚我应该放什么吗?有没有一种通用的方法可以知道对于任何给定的颜色贴图,白色是什么?

我想你在这方面有点倒退了。没有完全通用的方法来确定颜色贴图中的白色(它可能存在多次或根本不存在)

但是,您可以仅指定在使用多边形集合时多边形的边应为白色,同时仍对面使用颜色贴图。只需指定
edgecolors
,而不是
edgecolor
。这有点让人困惑,但它是复数的,因为可以指定多个值。还有,看看

举个简单的例子:

import matplotlib.pyplot as plt
from matplotlib.patches import RegularPolygon
from matplotlib.collections import PatchCollection
import numpy as np

xy = np.random.random((10,2))
z = np.random.random(10)

patches = [RegularPolygon((x,y), 5, 0.1) for x, y in xy]
collection = PatchCollection(patches, array=z, edgecolors='white', lw=2)

fig, ax = plt.subplots()
# So that the white edges show up...
ax.patch.set(facecolor='black')
ax.add_collection(collection)
ax.autoscale()

plt.show()