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
Quiver does not _init with animated=True and quiverkey attached #2616
Comments
Thanks for the bug report. It is easier to deal with bug reports that include complete examples to generate the issue http://sscce.org/ .
Confirmed on current master. |
Although it looks like there should be a very simple fix for this, I don't have it working yet. There is something going on with the transforms that I haven't figured out. @OceanWolf, regarding your question: the reason quiverkey is only an Axes method and pyplot function is that its functionality is inherently tied to a Quiver instance, which in turn is inherently tied to an Axes instance. |
@zhenghu2 Did you mean to post this to a different thread? I do not immediately see the relation to |
@tacaswell, it is related, but the @zhenghu2 fix simply defeats the purpose of the get_animated() method for everything. I think that purpose is to make it possible to draw everything but the animated artists, take a snapshot of it, and then animate by repeatedly drawing the artists on that snapshot. The problem is that part of the quiver initialization doesn't occur until drawing time (for good reason) but quiverkey needs the result of that initialization. I tried a simple fix but ran into a problem, and haven't been able to get back to it. |
Is it possible to give a more detailed description on what animated keyword is about? The example I posted is taken from here:
With animated set to True, the blue line did not show, which makes me think that its draw method is not called. Also in Quiver, _init is only called if the draw method is called. That's why I proposed that change. Or is animated keyword not intended to be used this way? |
@efiring Since there is a boolean variable Quiver._initialized(https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/quiver.py#L441) . Could it be used in QuiverKey._init to check if Quiver is been initialized? So QuiverKey._init will be changed to: def _init(self):
if True: # not self._initialized:
self._set_transform()
_pivot = self.Q.pivot
self.Q.pivot = self.pivot[self.labelpos]
# Hack: save and restore the Umask
_mask = self.Q.Umask
self.Q.Umask = ma.nomask
#changes----------------------------------------------
if not self.Q._initialized:
self.Q._init()
self.Q._initialized = True
#---------------------------------------------------------------------------
self.verts = self.Q._make_verts(np.array([self.U]),
np.zeros((1,)))
self.Q.Umask = _mask
self.Q.pivot = _pivot
kw = self.Q.polykw
kw.update(self.kw)
self.vector = mcollections.PolyCollection(
self.verts,
offsets=[(self.X, self.Y)],
transOffset=self.get_transform(),
**kw)
if self.color is not None:
self.vector.set_color(self.color)
self.vector.set_transform(self.Q.get_transform())
self.vector.set_figure(self.get_figure())
self._initialized = True |
@zhenghu2 I think that is what I tried, and as I said, there was a problem. If I remember correctly, it messed up either the vector scaling, or the quiverkey scaling. |
I have the solution and will provide a PR, but not right this minute. |
Added a test. Closes matplotlib#2616. Add new test image.
Added a test. Closes matplotlib#2616.
Added a test. Closes matplotlib#2616.
Creating a quiver object with animated=True and adding this to a quiver key, this fails
with
Obviously adding the optional width attribute to the quiver call, works as a dodgy workaround, but not the best as it neglects other code in the _init method. Note, using matplotlib version 1.1.1rc2
As a side issue, why can one not call quiverkey from the figure object? One can add both a colorbar and a legend from the figure object, so quiverkey seems the odd one out.
The text was updated successfully, but these errors were encountered: