compound
FancyBboxPatch 内にカプセル化されたテキストと画像を含む形状を描画できるアーティストを matplotlib で作成したいと考えています。前述の FancyBboxPatch からクラスを派生させ、「描画」メソッドをオーバーライドしましたが、機能していないようです。
私が達成しようとしているのは、matplotlib で描画可能なオブジェクトですが、利用可能な単純なパッチよりも複雑です。GUI 設計における複合ウィジェットの概念に少し似ています。
これが私が試したものです:
class Cell(FancyBboxPatch):
def __init__(self, xy, width, height, **kwargs):
FancyBboxPatch.__init__(self, xy, width, height, **kwargs)
def draw(self, renderer):
print "Overridden draw method"
FancyBboxPatch.draw(self, renderer)
# Try drawing some simple patches and text:
r = Rectangle((set._x, self._y), self._width, self._height)
r.draw(renderer) # this doesn't draw
t = Annotation("hi", (self._x, self._y))
t.draw(renderer) # this causes an error
しかし、これは機能しません。長方形は描画されず、注釈はエラーをスローします:AttributeError: 'NoneType' object has no attribute 'transData'
私はこれについて間違った方向に進んでいると感じています!draw
この方法でメソッドをオーバーライドできますか?
ティア