Thanks to visit codestin.com
Credit goes to github.com

Skip to content

YAArrow.figure gets overwritten during superclass construction #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2012

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Jun 7, 2012

SVN revision 4909 seems to have broken the YAArrow constructor by changing its dpi parameter to be figure instead, while Artist's constructor sets self.figure to None. Since YAArrow.__init__ calls the Patch constructor after setting self.figure, and the Patch constructor calls the Artist constructor, the constructed YAArrow object ends up with self.figure == None.

This causes YAArrow patches to not be usable in a PatchCollection because that constructor calls get_path, which attempts to access the YAArrow's dpi from the figure member:

    p = PatchCollection(patches, match_original=True)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/collections.py", line 1125, in __init__
    self.set_paths(patches)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/collections.py", line 1129, in set_paths
    for p in patches]
  File "/usr/local/lib/python2.7/site-packages/matplotlib/patches.py", line 1039, in get_path
    k1 = self.width*self.figure.dpi/72./2.
AttributeError: 'NoneType' object has no attribute 'dpi'

To work around the issue, it suffices to simply set the figure manually after constructing the YAArrow:

arrow = YAArrow(figure, (x,y), (x+dx, y+dy))
arrow.figure = figure

(For a diff of SVN revision 4909, see http://www.mail-archive.com/[email protected]/msg01214.html )

I'm using version 1.1.1~rc1+git20120423-0ubuntu1, but from scanning the source on github it looks as though the bug is still present.

@mdboom
Copy link
Member

mdboom commented Jun 7, 2012

Good catch. Can you confirm that the attached patch resolves your issue?

@diffusor
Copy link
Author

diffusor commented Jun 8, 2012

Yep, that does the trick, thanks!

Might I suggest that you also include a comment explaining why just that particular member gets set after Patch.__init__, perhaps something along the lines of:

    # This must be set after the superclass constructor, which sets figure = None (see issue 930 on github)

@diffusor diffusor closed this Jun 8, 2012
@diffusor diffusor reopened this Jun 8, 2012
@diffusor
Copy link
Author

diffusor commented Jun 8, 2012

(Whoops, I don't think I meant to close the pull request.)

mdboom added a commit that referenced this pull request Jun 8, 2012
YAArrow.figure gets overwritten during superclass construction
@mdboom mdboom merged commit f929f74 into matplotlib:v1.1.x Jun 8, 2012
@mdboom mdboom deleted the yaarrow_constructor branch March 3, 2015 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants