Skip to content
This repository

Quiver crashes if given matrices #1546

wants to merge 1 commit into from

3 participants

Gustav Larsson Benjamin Root Eric Firing
Gustav Larsson

As it is now, quiver() fails if you give it numpy.matrix objects, as this simple example shows:

>>> quiver(np.matrix(np.ones((32, 32))), np.matrix(np.ones((32, 32))))

It does so because it runs ravel() on the input, which if the input is a matrix gives a row matrix of shape (N, 1), instead of an array of shape (N,), which is what quiver expects in further calculations.

This pull request fixes this problem by running the input through np.asarray() before ravel() is called.

Benjamin Root
Eric Firing
Gustav Larsson

I see, yeah that's a problem. The function looked promising here, but it actually just converts a matrix into a masked matrix.

It's hard to realize what the problem is if you happen to do this though, so it would be great if we could spare the people who accidentally do this some headache, in any way possible. Should I just open up an issue?

Eric Firing

You could open an issue. Unless other developers think we should put in extensive matrix trapping, the solution would be to put clear "matrix inputs are not supported and may cause hard-to-diagnose errors" warnings in the documentation.

Thank you for pointing out the problem and proposing a solution, but I am going to close this pull request.

Eric Firing efiring closed this November 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 29, 2012
Gustav Larsson Fixed so that quiver does not fail if given matrices. 6e79055
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. 4  lib/matplotlib/
4  lib/matplotlib/
@@ -459,8 +459,8 @@ def draw(self, renderer):
459 459
         collections.PolyCollection.draw(self, renderer)
460 460
461 461
     def set_UVC(self, U, V, C=None):
-        U = ma.masked_invalid(U, copy=False).ravel()
-        V = ma.masked_invalid(V, copy=False).ravel()
+        U = ma.masked_invalid(np.asarray(U), copy=False).ravel()
+        V = ma.masked_invalid(np.asarray(V), copy=False).ravel()
464 464
         mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
465 465
         if C is not None:
466 466
             C = ma.masked_invalid(C, copy=False).ravel()

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.