Exemplo n.º 1
0
    def _process_args(self, *args, **kwargs):
        """
        Process args and kwargs.
        """
        if isinstance(args[0], TriContourSet):
            C = args[0].cppContourGenerator
            if self.levels is None:
                self.levels = args[0].levels
        else:
            tri, z = self._contour_args(args, kwargs)
            C = _tri.TriContourGenerator(tri.get_cpp_triangulation(), z)
            self._mins = [tri.x.min(), tri.y.min()]
            self._maxs = [tri.x.max(), tri.y.max()]

        self.cppContourGenerator = C
Exemplo n.º 2
0
    def _process_args(self, *args, **kwargs):
        """
        Process args and kwargs.
        """
        if isinstance(args[0], TriContourSet):
            C = args[0].cppContourGenerator
            if self.levels is None:
                self.levels = args[0].levels
        else:
            tri, z = self._contour_args(args, kwargs)
            C = _tri.TriContourGenerator(tri.get_cpp_triangulation(), z)
            x0 = tri.x.min()
            x1 = tri.x.max()
            y0 = tri.y.min()
            y1 = tri.y.max()
            self.ax.update_datalim([(x0, y0), (x1, y1)])
            self.ax.autoscale_view()

        self.cppContourGenerator = C
Exemplo n.º 3
0
    def _process_args(self, *args, **kwargs):
        """
        Process args and kwargs.
        """
        if isinstance(args[0], TriContourSet):
            C = args[0]._contour_generator
            if self.levels is None:
                self.levels = args[0].levels
            self.zmin = args[0].zmin
            self.zmax = args[0].zmax
            self._mins = args[0]._mins
            self._maxs = args[0]._maxs
        else:
            from matplotlib import _tri
            tri, z = self._contour_args(args, kwargs)
            C = _tri.TriContourGenerator(tri.get_cpp_triangulation(), z)
            self._mins = [tri.x.min(), tri.y.min()]
            self._maxs = [tri.x.max(), tri.y.max()]

        self._contour_generator = C
        return kwargs
Exemplo n.º 4
0
def test_internal_cpp_api():
    # Following github issue 8197.
    import matplotlib._tri as _tri

    # C++ Triangulation.
    with pytest.raises(TypeError) as excinfo:
        triang = _tri.Triangulation()
    excinfo.match(r'function takes exactly 7 arguments \(0 given\)')

    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation([], [1], [[]], None, None, None, False)
    excinfo.match(r'x and y must be 1D arrays of the same length')

    x = [0, 1, 1]
    y = [0, 0, 1]
    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, [[0, 1]], None, None, None, False)
    excinfo.match(r'triangles must be a 2D array of shape \(\?,3\)')

    tris = [[0, 1, 2]]
    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, tris, [0, 1], None, None, False)
    excinfo.match(r'mask must be a 1D array with the same length as the ' +
                  r'triangles array')

    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, tris, None, [[1]], None, False)
    excinfo.match(r'edges must be a 2D array with shape \(\?,2\)')

    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, tris, None, None, [[-1]], False)
    excinfo.match(r'neighbors must be a 2D array with the same shape as the ' +
                  r'triangles array')

    triang = _tri.Triangulation(x, y, tris, None, None, None, False)

    with pytest.raises(ValueError) as excinfo:
        triang.calculate_plane_coefficients([])
    excinfo.match(r'z array must have same length as triangulation x and y ' +
                  r'arrays')

    with pytest.raises(ValueError) as excinfo:
        triang.set_mask([0, 1])
    excinfo.match(r'mask must be a 1D array with the same length as the ' +
                  r'triangles array')

    # C++ TriContourGenerator.
    with pytest.raises(TypeError) as excinfo:
        tcg = _tri.TriContourGenerator()
    excinfo.match(r'function takes exactly 2 arguments \(0 given\)')

    with pytest.raises(ValueError) as excinfo:
        tcg = _tri.TriContourGenerator(triang, [1])
    excinfo.match(r'z must be a 1D array with the same length as the x and ' +
                  r'y arrays')

    z = [0, 1, 2]
    tcg = _tri.TriContourGenerator(triang, z)

    with pytest.raises(ValueError) as excinfo:
        tcg.create_filled_contour(1, 0)
    excinfo.match(r'filled contour levels must be increasing')

    # C++ TrapezoidMapTriFinder.
    with pytest.raises(TypeError) as excinfo:
        trifinder = _tri.TrapezoidMapTriFinder()
    excinfo.match(r'function takes exactly 1 argument \(0 given\)')

    trifinder = _tri.TrapezoidMapTriFinder(triang)

    with pytest.raises(ValueError) as excinfo:
        trifinder.find_many([0], [0, 1])
    excinfo.match(r'x and y must be array_like with same shape')