MCPcopy
hub / github.com/matplotlib/matplotlib / _pcolorargs

Method _pcolorargs

lib/matplotlib/axes/_axes.py:6393–6504  ·  view source on GitHub ↗
(self, funcname, *args, shading='auto', **kwargs)

Source from the content-addressed store, hash-verified

6391 return im
6392
6393 def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
6394 # - create X and Y if not present;
6395 # - reshape X and Y as needed if they are 1-D;
6396 # - check for proper sizes based on `shading` kwarg;
6397 # - reset shading if shading='auto' to flat or nearest
6398 # depending on size;
6399
6400 _valid_shading = ['gouraud', 'nearest', 'flat', 'auto']
6401 try:
6402 _api.check_in_list(_valid_shading, shading=shading)
6403 except ValueError:
6404 _api.warn_external(f"shading value '{shading}' not in list of "
6405 f"valid values {_valid_shading}. Setting "
6406 "shading='auto'.")
6407 shading = 'auto'
6408
6409 if len(args) == 1:
6410 C = np.asanyarray(args[0])
6411 nrows, ncols = C.shape[:2]
6412 if shading in ['gouraud', 'nearest']:
6413 X, Y = np.meshgrid(np.arange(ncols), np.arange(nrows))
6414 else:
6415 X, Y = np.meshgrid(np.arange(ncols + 1), np.arange(nrows + 1))
6416 shading = 'flat'
6417 elif len(args) == 3:
6418 # Check x and y for bad data...
6419 C = np.asanyarray(args[2])
6420 # unit conversion allows e.g. datetime objects as axis values
6421 X, Y = args[:2]
6422 X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
6423 X, Y = (cbook.safe_masked_invalid(a, copy=True) for a in [X, Y])
6424
6425 if funcname == 'pcolormesh':
6426 if np.ma.is_masked(X) or np.ma.is_masked(Y):
6427 raise ValueError(
6428 'x and y arguments to pcolormesh cannot have '
6429 'non-finite values or be of type '
6430 'numpy.ma.MaskedArray with masked values')
6431 nrows, ncols = C.shape[:2]
6432 else:
6433 raise _api.nargs_error(funcname, takes="1 or 3", given=len(args))
6434
6435 Nx = X.shape[-1]
6436 Ny = Y.shape[0]
6437 if X.ndim != 2 or X.shape[0] == 1:
6438 x = X.reshape(1, Nx)
6439 X = x.repeat(Ny, axis=0)
6440 if Y.ndim != 2 or Y.shape[1] == 1:
6441 y = Y.reshape(Ny, 1)
6442 Y = y.repeat(Nx, axis=1)
6443 if X.shape != Y.shape:
6444 raise TypeError(f'Incompatible X, Y inputs to {funcname}; '
6445 f'see help({funcname})')
6446
6447 if shading == 'auto':
6448 if ncols == Nx and nrows == Ny:
6449 shading = 'nearest'
6450 else:

Callers 2

pcolorMethod · 0.95
pcolormeshMethod · 0.95

Calls 1

_process_unit_infoMethod · 0.80

Tested by

no test coverage detected