'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 = Nrows - i - 0.5
If extent is not None, x and y will be scaled to match,
as in imshow.
If origin is None and extent is not None, then extent
will give the minimum and maximum values of x and y.'

def _initialize_x_y(self, z):

    if (z.ndim != 2):
        raise TypeError(u'Input    must    be    a    2D    array.')
    elif ((z.shape[0] < 2) or (z.shape[1] < 2)):
        raise TypeError(u'Input    z    must    be    at    least    a    2x2    array.')
    else:
        (Ny, Nx) = z.shape
    if (self.origin is None):
        if (self.extent is None):
            return np.meshgrid(np.arange(Nx), np.arange(Ny))
        else:
            (x0, x1, y0, y1) = self.extent
            x = np.linspace(x0, x1, Nx)
            y = np.linspace(y0, y1, Ny)
            return np.meshgrid(x, y)
    if (self.extent is None):
        (x0, x1, y0, y1) = (0, Nx, 0, Ny)
    else:
        (x0, x1, y0, y1) = self.extent
    dx = (float((x1 - x0)) / Nx)
    dy = (float((y1 - y0)) / Ny)
    x = (x0 + ((np.arange(Nx) + 0.5) * dx))
    y = (y0 + ((np.arange(Ny) + 0.5) * dy))
    if (self.origin == u'upper'):
        y = y[::(-1)]
    return np.meshgrid(x, y)
