MCPcopy
hub / github.com/matplotlib/matplotlib / _check_xyz

Method _check_xyz

lib/matplotlib/contour.py:1402–1443  ·  view source on GitHub ↗

Check that the shapes of the input arrays match; if x and y are 1D, convert them to 2D using meshgrid.

(self, x, y, z, kwargs)

Source from the content-addressed store, hash-verified

1400 return (x, y, z)
1401
1402 def _check_xyz(self, x, y, z, kwargs):
1403 """
1404 Check that the shapes of the input arrays match; if x and y are 1D,
1405 convert them to 2D using meshgrid.
1406 """
1407 x, y = self.axes._process_unit_info([("x", x), ("y", y)], kwargs)
1408
1409 x = np.asarray(x, dtype=np.float64)
1410 y = np.asarray(y, dtype=np.float64)
1411 z = ma.asarray(z)
1412
1413 if z.ndim != 2:
1414 raise TypeError(f"Input z must be 2D, not {z.ndim}D")
1415 if z.shape[0] < 2 or z.shape[1] < 2:
1416 raise TypeError(f"Input z must be at least a (2, 2) shaped array, "
1417 f"but has shape {z.shape}")
1418 Ny, Nx = z.shape
1419
1420 if x.ndim != y.ndim:
1421 raise TypeError(f"Number of dimensions of x ({x.ndim}) and y "
1422 f"({y.ndim}) do not match")
1423 if x.ndim == 1:
1424 nx, = x.shape
1425 ny, = y.shape
1426 if nx != Nx:
1427 raise TypeError(f"Length of x ({nx}) must match number of "
1428 f"columns in z ({Nx})")
1429 if ny != Ny:
1430 raise TypeError(f"Length of y ({ny}) must match number of "
1431 f"rows in z ({Ny})")
1432 x, y = np.meshgrid(x, y)
1433 elif x.ndim == 2:
1434 if x.shape != z.shape:
1435 raise TypeError(
1436 f"Shapes of x {x.shape} and z {z.shape} do not match")
1437 if y.shape != z.shape:
1438 raise TypeError(
1439 f"Shapes of y {y.shape} and z {z.shape} do not match")
1440 else:
1441 raise TypeError(f"Inputs x and y must be 1D or 2D, not {x.ndim}D")
1442
1443 return x, y, z
1444
1445 def _initialize_x_y(self, z):
1446 """

Callers 1

_contour_argsMethod · 0.95

Calls 1

_process_unit_infoMethod · 0.80

Tested by

no test coverage detected