Return X, Y arrays such that contour(Z) will match imshow(Z) if origin is not None. The center of pixel Z[i, j] depends on origin: if origin is None, x = j, y = i; if origin is 'lower', x = j + 0.5, y = i + 0.5; if origin is 'upper', x = j + 0.5, y =
(self, z)
| 1443 | return x, y, z |
| 1444 | |
| 1445 | def _initialize_x_y(self, z): |
| 1446 | """ |
| 1447 | Return X, Y arrays such that contour(Z) will match imshow(Z) |
| 1448 | if origin is not None. |
| 1449 | The center of pixel Z[i, j] depends on origin: |
| 1450 | if origin is None, x = j, y = i; |
| 1451 | if origin is 'lower', x = j + 0.5, y = i + 0.5; |
| 1452 | if origin is 'upper', x = j + 0.5, y = Nrows - i - 0.5 |
| 1453 | If extent is not None, x and y will be scaled to match, |
| 1454 | as in imshow. |
| 1455 | If origin is None and extent is not None, then extent |
| 1456 | will give the minimum and maximum values of x and y. |
| 1457 | """ |
| 1458 | if z.ndim != 2: |
| 1459 | raise TypeError(f"Input z must be 2D, not {z.ndim}D") |
| 1460 | elif z.shape[0] < 2 or z.shape[1] < 2: |
| 1461 | raise TypeError(f"Input z must be at least a (2, 2) shaped array, " |
| 1462 | f"but has shape {z.shape}") |
| 1463 | else: |
| 1464 | Ny, Nx = z.shape |
| 1465 | if self.origin is None: # Not for image-matching. |
| 1466 | if self.extent is None: |
| 1467 | return np.meshgrid(np.arange(Nx), np.arange(Ny)) |
| 1468 | else: |
| 1469 | x0, x1, y0, y1 = self.extent |
| 1470 | x = np.linspace(x0, x1, Nx) |
| 1471 | y = np.linspace(y0, y1, Ny) |
| 1472 | return np.meshgrid(x, y) |
| 1473 | # Match image behavior: |
| 1474 | if self.extent is None: |
| 1475 | x0, x1, y0, y1 = (0, Nx, 0, Ny) |
| 1476 | else: |
| 1477 | x0, x1, y0, y1 = self.extent |
| 1478 | dx = (x1 - x0) / Nx |
| 1479 | dy = (y1 - y0) / Ny |
| 1480 | x = x0 + (np.arange(Nx) + 0.5) * dx |
| 1481 | y = y0 + (np.arange(Ny) + 0.5) * dy |
| 1482 | if self.origin == 'upper': |
| 1483 | y = y[::-1] |
| 1484 | return np.meshgrid(x, y) |
| 1485 | |
| 1486 | |
| 1487 | _docstring.interpd.register(contour_doc=""" |