# matplotlib/matplotlib

### Subversion checkout URL

You can clone with
or
.

# Improved checking logic of _check_xyz in contour.py#1471

Merged
merged 3 commits into from
+171 −9

### 3 participants

At the moment, if one calls `contour` with:

``````contour(x,y,z)
``````

and `x` and `y` are 2-d arrays with a different shape from `z`, the error is

``````raise TypeError("Inputs x and y must be 1D or 2D.")
``````

which caused me much confusion. I dug into the code, and I realized the logic and errors could be significantly improved, so I've done that here, and added some tests. It should now give more informative/relevant errors.

commented on an outdated diff
lib/matplotlib/tests/test_contour.py
 @@ -0,0 +1,127 @@ +import numpy as np +from matplotlib import pyplot as plt
 Collaborator pelson added a note Nov 9, 2012 FYI: All tests which use pyplot should either be an image test, or use the cleanup decroator. astrofrog added a note Nov 9, 2012 Ok, thanks! Added. to join this conversation on GitHub. Already have an account? Sign in to comment

@pelson - the tests appear to be passing now.

Collaborator

+1

commented on an outdated diff
lib/matplotlib/contour.py
 ((18 lines not shown)) + + nx, = x.shape + ny, = y.shape + + if nx != Nx: + raise TypeError("Length of x must be number of columns in z.") + + if ny != Ny: + raise TypeError("Length of y must be number of rows in z.") + + x, y = np.meshgrid(x, y) + + elif x.ndim == 2: + + if x.shape != z.shape: + raise TypeError("Shape of x does not match that of z: found {0} instead of {1}.".format(x.shape, z.shape))
 Collaborator dmcdougall added a note Nov 12, 2012 This and the `TypeError` below stretch to longer than 78 characters. In lieu of porting the codebase to be PEP8 compliant, could you wrap these and any other lines that are too long? astrofrog added a note Nov 12, 2012 This should be fixed now. to join this conversation on GitHub. Already have an account? Sign in to comment
Collaborator

 astrofrog `Improved checking logic of _check_xyz in contour.py, added tests for …` `…exceptions` `4910610` astrofrog `Add @cleanup decorator to new contour tests` `223d75a` astrofrog `Wrap lines for PEP8 compliance` `75336c4`

@pelson - done! All tests seem to pass on Travis.

merged commit `8de33d0` into matplotlib:master

#### 1 check passed

Details default The Travis build passed
`…exceptions`