2

このコンストラクターを使用してRegularPolygonsの束を作成します-

        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)

edgecolor = (whatever_white_is)

このコンストラクターで-

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)などを試しました。誰かが私が何をすべきかを理解するのを手伝ってくれますか?置く?特定のカラーマップの白が何であるかを知る一般的な方法はありますか?

4

1 に答える 1

1

私はあなたがこれについて少し後退していると思います。カラーマップ内の白を決定する完全に一般的な方法はありません (複数回存在するか、まったく存在しない可能性があります)。

ただし、PolyCollection を使用する場合は、面のカラーマップを引き続き使用しながら、ポリゴンのエッジを白にするように指定できます。edgecolorsの代わりに指定するだけですedgecolor。少し紛らわしいですが、複数の値を指定できるため、複数形であるという考え方です。また、ご覧くださいRegularPolygonCollection

簡単な例として:

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()

ここに画像の説明を入力

于 2013-02-03T18:03:32.787 に答える