예제 #1
0
    def plot_n_matrices_eigenvectors(self, n, side='right', color_index=0, draw_line=False):
        r"""
        INPUT:

        - ``n`` -- integer, length
        - ``side`` -- ``'left'`` or ``'right'``, drawing left or right
          eigenvectors
        - ``color_index`` -- 0 for first letter, -1 for last letter
        - ``draw_line`` -- boolean

        EXAMPLES::

            sage: from slabbe.matrix_cocycle import cocycles
            sage: ARP = cocycles.ARP()
            sage: G = ARP.plot_n_matrices_eigenvectors(2)
        """
        from sage.plot.graphics import Graphics
        from sage.plot.point import point
        from sage.plot.line import line
        from sage.plot.text import text
        from sage.plot.colors import hue
        from sage.modules.free_module_element import vector
        from matrices import M3to2
        R = self.n_matrices_eigenvectors(n)
        L = [(w, M3to2*(a/sum(a)), M3to2*(b/sum(b))) for (w,a,b) in R]
        G = Graphics()
        alphabet = self._language._alphabet
        color_ = dict( (letter, hue(i/float(len(alphabet)))) for i,letter in
                enumerate(alphabet))
        for letter in alphabet:
            L_filtered = [(w,p1,p2) for (w,p1,p2) in L if w[color_index] == letter]
            words,rights,lefts = zip(*L_filtered)
            if side == 'right':
                G += point(rights, color=color_[letter], legend_label=letter)
            elif side == 'left':
                G += point(lefts,  color=color_[letter], legend_label=letter)
            else:
                raise ValueError("side(=%s) should be left or right" % side)

        if draw_line:
            for (a,b) in L:
                G += line([a,b], color='black', linestyle=":")
        G += line([M3to2*vector(a) for a in [(1,0,0), (0,1,0), (0,0,1), (1,0,0)]]) 
        title = "%s eigenvectors, colored by letter w[%s] of cylinder w" % (side, color_index)
        G += text(title, (0.5, 1.05), axis_coords=True)
        G.axes(False)
        return G
예제 #2
0
    def plot_n_matrices_eigenvectors(self, n, side='right', color_index=0, draw_line=False):
        r"""
        INPUT:

        - ``n`` -- integer, length
        - ``side`` -- ``'left'`` or ``'right'``, drawing left or right
          eigenvectors
        - ``color_index`` -- 0 for first letter, -1 for last letter
        - ``draw_line`` -- boolean

        EXAMPLES::

            sage: from slabbe.matrix_cocycle import cocycles
            sage: ARP = cocycles.ARP()
            sage: G = ARP.plot_n_matrices_eigenvectors(2)
        """
        from sage.plot.graphics import Graphics
        from sage.plot.point import point
        from sage.plot.line import line
        from sage.plot.text import text
        from sage.plot.colors import hue
        from sage.modules.free_module_element import vector
        from .matrices import M3to2
        R = self.n_matrices_eigenvectors(n)
        L = [(w, M3to2*(a/sum(a)), M3to2*(b/sum(b))) for (w,a,b) in R]
        G = Graphics()
        alphabet = self._language._alphabet
        color_ = dict( (letter, hue(i/float(len(alphabet)))) for i,letter in
                enumerate(alphabet))
        for letter in alphabet:
            L_filtered = [(w,p1,p2) for (w,p1,p2) in L if w[color_index] == letter]
            words,rights,lefts = zip(*L_filtered)
            if side == 'right':
                G += point(rights, color=color_[letter], legend_label=letter)
            elif side == 'left':
                G += point(lefts,  color=color_[letter], legend_label=letter)
            else:
                raise ValueError("side(=%s) should be left or right" % side)

        if draw_line:
            for (a,b) in L:
                G += line([a,b], color='black', linestyle=":")
        G += line([M3to2*vector(a) for a in [(1,0,0), (0,1,0), (0,0,1), (1,0,0)]]) 
        title = "%s eigenvectors, colored by letter w[%s] of cylinder w" % (side, color_index)
        G += text(title, (0.5, 1.05), axis_coords=True)
        G.axes(False)
        return G
예제 #3
0
파일: primitive.py 프로젝트: chos9/sage
    def options(self):
        """
        Return the dictionary of options for this graphics primitive.

        By default this function verifies that the options are all
        valid; if any aren't, then a verbose message is printed with level 0.

        EXAMPLES::

            sage: from sage.plot.primitive import GraphicPrimitive
            sage: GraphicPrimitive({}).options()
            {}
        """
        from sage.plot.graphics import do_verify
        from sage.plot.colors import hue
        O = dict(self._options)
        if do_verify:
            A = self._allowed_options()
            t = False
            K = A.keys() + ['xmin', 'xmax', 'ymin', 'ymax', 'axes']
            for k in O.keys():
                if not k in K:
                    do_verify = False
                    verbose("WARNING: Ignoring option '%s'=%s"%(k,O[k]), level=0)
                    t = True
            if t:
                s = "\nThe allowed options for %s are:\n"%self
                K.sort()
                for k in K:
                    if A.has_key(k):
                        s += "    %-15s%-60s\n"%(k,A[k])
                verbose(s, level=0)


        if 'hue' in O:
            t = O['hue']
            if not isinstance(t, (tuple,list)):
                t = [t,1,1]
            O['rgbcolor'] = hue(*t)
            del O['hue']
        return O
예제 #4
0
    def options(self):
        """
        Return the dictionary of options for this graphics primitive.

        By default this function verifies that the options are all
        valid; if any aren't, then a verbose message is printed with level 0.

        EXAMPLES::

            sage: from sage.plot.primitive import GraphicPrimitive
            sage: GraphicPrimitive({}).options()
            {}
        """
        from sage.plot.plot import do_verify
        from sage.plot.colors import hue
        O = dict(self.__options)
        if do_verify:
            A = self._allowed_options()
            t = False
            K = A.keys() + ['xmin', 'xmax', 'ymin', 'ymax', 'axes']
            for k in O.keys():
                if not k in K:
                    do_verify = False
                    verbose("WARNING: Ignoring option '%s'=%s" % (k, O[k]),
                            level=0)
                    t = True
            if t:
                s = "\nThe allowed options for %s are:\n" % self
                K.sort()
                for k in K:
                    if A.has_key(k):
                        s += "    %-15s%-60s\n" % (k, A[k])
                verbose(s, level=0)

        if 'hue' in O:
            t = O['hue']
            if not isinstance(t, (tuple, list)):
                t = [t, 1, 1]
            O['rgbcolor'] = hue(*t)
            del O['hue']
        return O
예제 #5
0
        self._max = max(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])

        # jump in and start building blocks
        outer = self.plot_block(min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z,
                                nw_z, se_z, ne_z, mid_z, 0)

        # build the boundary triangles
        self.triangulate(outer.left, outer.left_c)
        self.triangulate(outer.top, outer.top_c)
        self.triangulate(outer.right, outer.right_c)
        self.triangulate(outer.bottom, outer.bottom_c)

        zrange = self._max - self._min
        if num_colors is not None and zrange != 0:
            colors = triangle_factory.get_colors(
                [hue(float(i / num_colors)) for i in range(num_colors)])

            for o in self._objects:
                vertices = o.get_vertices()
                avg_z = (vertices[0][2] + vertices[1][2] + vertices[2][2]) / 3
                o.set_color(colors[int(num_colors * (avg_z - self._min) /
                                       zrange)])

    def plot_block(self, min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z, nw_z,
                   se_z, ne_z, mid_z, depth):
        """
        Recursive triangulation function for plotting.
        First six inputs are scalars, next 5 are 2-dimensional lists, and the depth argument
        keeps track of the depth of recursion.

        TESTS::
예제 #6
0
    def __init__(self,
                 triangle_factory,
                 f,
                 min_x__max_x,
                 min_y__max_y,
                 g=None,
                 min_depth=4,
                 max_depth=8,
                 num_colors=None,
                 max_bend=.3):
        """

        TESTS::

            sage: from sage.plot.plot3d.tri_plot import TrianglePlot, TriangleFactory
            sage: tf = TriangleFactory()
            sage: t = TrianglePlot(tf, lambda x,y: x^2+y^2, (0, 1), (0, 1))
            sage: t._f(1,1)
            2
        """
        (min_x, max_x) = min_x__max_x
        (min_y, max_y) = min_y__max_y
        self._triangle_factory = triangle_factory
        self._f = f
        self._g = g
        self._min_depth = min_depth
        self._max_depth = max_depth
        self._max_bend = max_bend
        self._objects = []
        if min(max_x - min_x, max_y - min_y) == 0:
            raise ValueError(
                'Plot rectangle is really a line.  Make sure min_x != max_x and min_y != max_y.'
            )
        self._num_colors = num_colors
        if g is None:

            def fcn(x, y):
                return [self._f(x, y)]
        else:

            def fcn(x, y):
                return [self._f(x, y), self._g(x, y)]

        self._fcn = fcn

        # generate the necessary data to kick-start the recursion
        mid_x = (min_x + max_x) / 2
        mid_y = (min_y + max_y) / 2
        sw_z = fcn(min_x, min_y)
        nw_z = fcn(min_x, max_y)
        se_z = fcn(max_x, min_y)
        ne_z = fcn(max_x, max_y)
        mid_z = fcn(mid_x, mid_y)

        self._min = min(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])
        self._max = max(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])

        # jump in and start building blocks
        outer = self.plot_block(min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z,
                                nw_z, se_z, ne_z, mid_z, 0)

        # build the boundary triangles
        self.triangulate(outer.left, outer.left_c)
        self.triangulate(outer.top, outer.top_c)
        self.triangulate(outer.right, outer.right_c)
        self.triangulate(outer.bottom, outer.bottom_c)

        zrange = self._max - self._min
        if num_colors is not None and zrange != 0:
            colors = triangle_factory.get_colors(
                [hue(float(i / num_colors)) for i in range(num_colors)])

            for o in self._objects:
                vertices = o.get_vertices()
                avg_z = (vertices[0][2] + vertices[1][2] + vertices[2][2]) / 3
                o.set_color(colors[int(num_colors * (avg_z - self._min) /
                                       zrange)])
예제 #7
0
        self._min = min(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])
        self._max = max(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])

        # jump in and start building blocks
        outer = self.plot_block(min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z, nw_z, se_z, ne_z, mid_z, 0)

        # build the boundary triangles
        self.triangulate(outer.left, outer.left_c)
        self.triangulate(outer.top, outer.top_c)
        self.triangulate(outer.right, outer.right_c)
        self.triangulate(outer.bottom, outer.bottom_c)

        zrange = self._max - self._min
        if num_colors is not None and zrange != 0:
            colors = triangle_factory.get_colors([hue(float(i/num_colors)) for i in range(num_colors)])

            for o in self._objects:
                vertices = o.get_vertices()
                avg_z = (vertices[0][2] + vertices[1][2] + vertices[2][2])/3
                o.set_color(colors[int(num_colors * (avg_z - self._min) / zrange)])

    def plot_block(self, min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z, nw_z, se_z, ne_z, mid_z, depth):
        """
        Recursive triangulation function for plotting.
        First six inputs are scalars, next 5 are 2-dimensional lists, and the depth argument
        keeps track of the depth of recursion.

        TESTS::

            sage: from sage.plot.plot3d.tri_plot import TrianglePlot, TriangleFactory
예제 #8
0
    def __init__(self, triangle_factory, f, min_x__max_x, min_y__max_y, g = None,
                       min_depth=4, max_depth=8, num_colors = None, max_bend=.3):
        """

        TESTS::

            sage: from sage.plot.plot3d.tri_plot import TrianglePlot, TriangleFactory
            sage: tf = TriangleFactory()
            sage: t = TrianglePlot(tf, lambda x,y: x^2+y^2, (0, 1), (0, 1))
            sage: t._f(1,1)
            2
        """
        (min_x, max_x) = min_x__max_x 
        (min_y, max_y) = min_y__max_y
        self._triangle_factory = triangle_factory
        self._f = f
        self._g = g
        self._min_depth = min_depth
        self._max_depth = max_depth
        self._max_bend = max_bend
        self._objects = []
        if min(max_x - min_x, max_y - min_y) == 0:
            raise ValueError('Plot rectangle is really a line.  Make sure min_x != max_x and min_y != max_y.')
        self._num_colors = num_colors
        if g is None:
            def fcn(x,y):
                return [self._f(x,y)]
        else:
            def fcn(x,y):
                return [self._f(x,y), self._g(x,y)]

        self._fcn = fcn


        # generate the necessary data to kick-start the recursion
        mid_x = (min_x + max_x)/2
        mid_y = (min_y + max_y)/2
        sw_z = fcn(min_x,min_y)
        nw_z = fcn(min_x,max_y)
        se_z = fcn(max_x,min_y)
        ne_z = fcn(max_x,max_y)
        mid_z = fcn(mid_x,mid_y)

        self._min = min(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])
        self._max = max(sw_z[0], nw_z[0], se_z[0], ne_z[0], mid_z[0])

        # jump in and start building blocks
        outer = self.plot_block(min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z, nw_z, se_z, ne_z, mid_z, 0)

        # build the boundary triangles
        self.triangulate(outer.left, outer.left_c)
        self.triangulate(outer.top, outer.top_c)
        self.triangulate(outer.right, outer.right_c)
        self.triangulate(outer.bottom, outer.bottom_c)

        zrange = self._max - self._min
        if num_colors is not None and zrange != 0:
            colors = triangle_factory.get_colors([hue(float(i/num_colors)) for i in range(num_colors)])

            for o in self._objects:
                vertices = o.get_vertices()
                avg_z = (vertices[0][2] + vertices[1][2] + vertices[2][2])/3
                o.set_color(colors[int(num_colors * (avg_z - self._min) / zrange)])