Example #1
0
    def __init__(self, xdata, ydata, options):
        """
        Initializes base class Polygon.

        EXAMPLES::

            sage: P = polygon([(0,0), (1,1), (-1,3)], thickness=2)
            sage: P[0].xdata
            [0.0, 1.0, -1.0]
            sage: P[0].options()['thickness']
            2
        """
        self.xdata = xdata
        self.ydata = ydata
        GraphicPrimitive_xydata.__init__(self, options)
Example #2
0
    def __init__(self, xdata, ydata, options):
        """
        Initializes base class Point.

        EXAMPLES::

            sage: P = point((3,4))
            sage: P[0].xdata
            [3.0]
            sage: P[0].options()['alpha']
            1
        """
        self.xdata = xdata
        self.ydata = ydata
        GraphicPrimitive_xydata.__init__(self, options)
Example #3
0
    def __init__(self, xdata, ydata, options):
        """
        Initializes base class Polygon.

        EXAMPLES::

            sage: P = polygon([(0,0), (1,1), (-1,3)], thickness=2)
            sage: P[0].xdata
            [0.0, 1.0, -1.0]
            sage: P[0].options()['thickness']
            2
        """
        self.xdata = xdata
        self.ydata = ydata
        GraphicPrimitive_xydata.__init__(self, options)
Example #4
0
File: point.py Project: bukzor/sage
    def __init__(self, xdata, ydata, options):
        """
        Initializes base class Point.

        EXAMPLES::

            sage: P = point((3,4))
            sage: P[0].xdata
            [3.0]
            sage: P[0].options()['alpha']
            1
        """
        self.xdata = xdata
        self.ydata = ydata
        GraphicPrimitive_xydata.__init__(self, options)
Example #5
0
    def __init__(self, path, options):
        """
        Returns a graphics primitive of a path of Bezier curves.

        EXAMPLES::

            sage: from sage.plot.bezier_path import BezierPath
            sage: BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], {'linestyle':'dashed'})
            Bezier path from (0.0, 0.0) to (0.0, 0.0)

            sage: BezierPath([[(0,0), (1,2), (3,6), (2,-1), (3,3)]], {})
            Traceback (most recent call last):
            ...
            ValueError: invalid input for BezierPath

        TESTS:

        Check :trac:`31646`::

            sage: from sage.plot.bezier_path import BezierPath
            sage: p2d = [[(3,0),(4,1),(2,1),(3,0)], [(2,2),(3,1),(2,1)]]
            sage: P = BezierPath(p2d, {})
            sage: P.path
            [array([[3., 0.], [4., 1.], [2., 1.], [3., 0.]]),
             array([[2., 2.], [3., 1.], [2., 1.]])]
        """
        import numpy as np

        self.path = [np.array(l, float) for l in path]

        # In oder to feed later to matplotlib.path.Path we convert in the following form
        # - vertices: an Nx2 float array of vertices
        # - codes: an N-length uint8 array of vertex types, or None
        #   where each code could be MOVETO (=1), LINETO (=2), CURVE3 (=3), CURVE4 (=4)
        self.vertices = np.concatenate(self.path)
        N, _ = self.vertices.shape
        codes = np.zeros((N,), np.uint8)
        k = 0
        for i, curve in enumerate(self.path):
            code = len(curve) + (i > 0)
            if code < 2 or code > 4:
                raise ValueError('invalid input for BezierPath')
            codes[k:k+len(curve)] = code
            k += len(curve)
        codes[0] = 1 # MOVETO
        self.codes = codes
        GraphicPrimitive_xydata.__init__(self, options)
Example #6
0
File: line.py Project: bukzor/sage
    def __init__(self, xdata, ydata, options):
        """
        Initialize a line graphics primitive.

        EXAMPLES::

            sage: from sage.plot.line import Line
            sage: Line([-1,2], [17,4], {'thickness':2})
            Line defined by 2 points
        """
        valid_options = self._allowed_options().keys()
        for opt in options.iterkeys():
            if opt not in valid_options:
                raise RuntimeError("Error in line(): option '%s' not valid."%opt)
        self.xdata = xdata
        self.ydata = ydata
        GraphicPrimitive_xydata.__init__(self, options)
Example #7
0
File: line.py Project: yjjcc/sage
    def __init__(self, xdata, ydata, options):
        """
        Initialize a line graphics primitive.

        EXAMPLES::

            sage: from sage.plot.line import Line
            sage: Line([-1,2], [17,4], {'thickness':2})
            Line defined by 2 points
        """
        valid_options = self._allowed_options()
        for opt in options:
            if opt not in valid_options:
                raise RuntimeError("Error in line(): option '%s' not valid." % opt)
        self.xdata = xdata
        self.ydata = ydata
        GraphicPrimitive_xydata.__init__(self, options)
Example #8
0
    def __init__(self, path, options):
        """
        Returns a graphics primitive of a path of Bezier curves.

        EXAMPLES::

            sage: from sage.plot.bezier_path import BezierPath
            sage: BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]],{'linestyle':'dashed'})
            Bezier path from (0, 0) to (0, 0)
        """
        import numpy as np
        self.path = path
        codes = [1] + (len(self.path[0])-1)*[len(self.path[0])]
        vertices = self.path[0]
        for curve in self.path[1:]:
            vertices += curve
            codes += (len(curve))*[len(curve)+1]
        self.codes = codes
        self.vertices = np.array(vertices, np.float)
        GraphicPrimitive_xydata.__init__(self, options)