def plot(self, color=None):
     r"""
     EXAMPLES::
     
         from flatsurf.geometry.similarity_surface_generators import SimilaritySurfaceGenerators
         s=SimilaritySurfaceGenerators.example()
         from flatsurf.graphical.surface import GraphicalSurface
         gs=GraphicalSurface(s)
         gs.make_visible(1)
         from flatsurf.geometry.tangent_bundle import *
         tb = SimilaritySurfaceTangentBundle(s)
         V=tb.surface().vector_space()
         v=SimilaritySurfaceTangentVector(tb, 0, V((1,-0.5)), V((3,-1)))
         from flatsurf.geometry.straight_line_trajectory import *
         seg = SegmentInPolygon(v)
         from flatsurf.graphical.straight_line_trajectory import *
         gseg = GraphicalSegmentInPolygon(gs, seg)
         show(gs.plot()+gseg.plot())
     """
     if self._gs.is_visible(self.polygon_label()):
         if color==None:
             color="black"
         from sage.plot.line import line2d
         return line2d([self.start(), self.end()],color=color)
     else:
         from sage.plot.graphics import Graphics
         return Graphics()
Example #2
0
    def plot_function(self, **d):
        r"""
        Return a plot of the interval exchange transformation as a
        function.

        INPUT:

        - Any option that is accepted by line2d

        OUTPUT:

        2d plot -- a plot of the iet as a function

        EXAMPLES::

            sage: t = iet.IntervalExchangeTransformation(('a b c d','d a c b'),[1,1,1,1])
            sage: t.plot_function(rgbcolor=(0,1,0))
            Graphics object consisting of 4 graphics primitives
        """
        from sage.plot.all import Graphics
        from sage.plot.line import line2d

        G = Graphics()
        l = self.singularities()
        t = self._permutation._twin

        for i in range(len(self._permutation)):
            j = t[0][i]
            G += line2d([(l[0][i], l[1][j]), (l[0][i + 1], l[1][j + 1])], **d)

        return G
Example #3
0
    def plot(self, color=None):
        r"""
        EXAMPLES::

            sage: from flatsurf import *
            sage: s = similarity_surfaces.example()
            sage: v = s.tangent_vector(0, (1,-0.5), (3,-1))
            sage: from flatsurf.geometry.straight_line_trajectory import SegmentInPolygon
            sage: seg = SegmentInPolygon(v)
            sage: from flatsurf.graphical.straight_line_trajectory import *
            sage: gseg = GraphicalSegmentInPolygon(s.graphical_surface(), seg)
            sage: gseg.plot()
            Graphics object consisting of 1 graphics primitive
            sage: gseg.plot(color='red')
            Graphics object consisting of 1 graphics primitive
        """
        if self._gs.is_visible(self.polygon_label()):
            if color is None:
                if self._color is None:
                    color = "black"
                else:
                    color = self._color
            from sage.plot.line import line2d
            return line2d([self.start(), self.end()],color=color)
        else:
            from sage.plot.graphics import Graphics
            return Graphics()
Example #4
0
File: iet.py Project: sagemath/sage
    def plot_function(self,**d):
        r"""
        Return a plot of the interval exchange transformation as a
        function.

        INPUT:

        - Any option that is accepted by line2d

        OUTPUT:

        2d plot -- a plot of the iet as a function

        EXAMPLES::

            sage: t = iet.IntervalExchangeTransformation(('a b c d','d a c b'),[1,1,1,1])
            sage: t.plot_function(rgbcolor=(0,1,0))
            Graphics object consisting of 4 graphics primitives
        """
        from sage.plot.all import Graphics
        from sage.plot.line import line2d

        G = Graphics()
        l = self.singularities()
        t = self._permutation._twin

        for i in range(len(self._permutation)):
            j = t[0][i]
            G += line2d([(l[0][i],l[1][j]),(l[0][i+1],l[1][j+1])],**d)

        return G
Example #5
0
    def plot_edge(self, e, color=None, dotted=False):
        ne = self.base_polygon().num_edges()
        if color is None:
            color = self._outline_color
        if color is None:
            from sage.plot.graphics import Graphics

            return Graphics()

        from sage.plot.line import line2d

        v = self._v[e]
        w = self._v[(e + 1) % ne]
        if dotted:
            return line2d([v, w], color=color, linestyle=":")
        else:
            return line2d([v, w], color=color)
Example #6
0
    def plot_edge(self, e, **options):
        r"""
        Plot the edge e, with e a number 0,...,n-1 with n being the number
        of edges of the polygon.

        Options are processed as in sage.plot.line.line2d.
        """
        return line2d([self._v[e], self._v[(e+1)%self.base_polygon().num_edges()]], \
            **options)
Example #7
0
    def plot_edge(self, e, **options):
        r"""
        Plot the edge e, with e a number 0,...,n-1 with n being the number
        of edges of the polygon.

        Options are processed as in sage.plot.line.line2d.
        """
        return line2d([self._v[e], self._v[(e+1)%self.base_polygon().num_edges()]], \
            **options)
 def plot_line(self):
     from sage.plot.line import line2d
     from sage.plot.point import point
     p = line2d([[0, 0], [1, 0]])
     for a in self._alpha:
         p += point([a, 0], color='blue', size=100)
     for b in self._beta:
         p += point([b, 0], color='red', size=100)
     p.show(axes=False, xmin=0, xmax=1, ymin=-.1, ymax=.1)
 def plot_line(self):
     from sage.plot.line import line2d
     from sage.plot.point import point
     p = line2d([[0,0],[1,0]])
     for a in self._alpha:
         p += point([a,0], color='blue', size=100)
     for b in self._beta:
         p += point([b,0], color='red', size=100)
     p.show(axes=False, xmin=0, xmax=1, ymin=-.1, ymax=.1)
Example #10
0
 def plot(self, translation=None):
     r"""
     Plot the polygon with the origin at ``translation``.
     """
     from sage.plot.point import point2d
     from sage.plot.line import line2d
     from sage.plot.polygon import polygon2d
     from sage.modules.free_module import VectorSpace
     V = VectorSpace(RR,2)
     P = self.vertices(translation)
     return point2d(P, color='red') + line2d(P + (P[0],), color='orange') + polygon2d(P, alpha=0.3)
Example #11
0
    def plot_zero_flag(self, **options):
        r"""
        Draw a line segment from the zero vertex toward the baricenter.

        A real parameter ``t`` can be provided. If t=1, then the segment will
        go all the way to the baricenter.  The value of ``t`` is linear in the
        length of the segment. Defaults to t=0.5.

        Other options are processed as in sage.plot.line.line2d.
        """
        if "t" in options:
            t = RDF(options.pop("t"))
        else:
            t = 0.5

        return line2d([self._v[0], self._v[0] + t*(sum(self._v) / len(self._v) - self._v[0])],
            **options)
Example #12
0
 def plot_profile(self):
     from sage.plot.line import line2d
     from sage.plot.point import point
     from sage.plot.text import text
     p_color, p_number, p_ev = self.profile()
     d = len(p_color)
     color = lambda i: 'blue' if p_color[i] else 'red'
     p = lambda i: [0,0] if i == -1 else [i+1,p_number[i]]
     plt = point([0,0],marker='x',size=100)
     for i in range(d):
         plt += line2d([p(i-1),p(i)],alpha=.5)
         plt += point(p(i), color=color(i), size=100)
         if p_color[i]:
             [x,y] = p(i)
             plt += text(r"$\alpha_%i$"%(self._i_alpha[p_ev[i]]+1), [x,y+.2], fontsize = 40)
         else:
             [x,y] = p(i)
             plt += text(r"$\beta_%i$"%(self._i_beta[p_ev[i]]+1), [x,y+.2], fontsize = 40)
     plt.show(axes=False, ymin=0, xmin=0, xmax=d)
Example #13
0
    def plot_zero_flag(self, **options):
        r"""
        Draw a line segment from the zero vertex toward the baricenter.

        A real parameter ``t`` can be provided. If t=1, then the segment will
        go all the way to the baricenter.  The value of ``t`` is linear in the
        length of the segment. Defaults to t=0.5.

        Other options are processed as in sage.plot.line.line2d.
        """
        if "t" in options:
            t = RDF(options.pop("t"))
        else:
            t = 0.5

        return line2d([
            self._v[0], self._v[0] + t *
            (sum(self._v) / len(self._v) - self._v[0])
        ], **options)
    def plot(self, **options):
        r"""
        EXAMPLES::

            sage: from flatsurf import *
            sage: s = similarity_surfaces.example()
            sage: v = s.tangent_vector(0, (1,-0.5), (3,-1))
            sage: from flatsurf.geometry.straight_line_trajectory import SegmentInPolygon
            sage: seg = SegmentInPolygon(v)
            sage: from flatsurf.graphical.straight_line_trajectory import *
            sage: gseg = GraphicalSegmentInPolygon(seg, s.graphical_surface())
            sage: gseg.plot()                # not tested (problem with matplotlib font caches on Travis)
            Graphics object consisting of 1 graphics primitive
            sage: gseg.plot(color='red')     # not tested (problem with matplotlib font caches on Travis)
            Graphics object consisting of 1 graphics primitive
        """
        if self._gs.is_visible(self.polygon_label()):
            from sage.plot.line import line2d
            return line2d([self.start(), self.end()],**options)
        else:
            from sage.plot.graphics import Graphics
            return Graphics()
Example #15
0
 def plot_profile(self):
     from sage.plot.line import line2d
     from sage.plot.point import point
     from sage.plot.text import text
     p_color, p_number, p_ev = self.profile()
     d = len(p_color)
     color = lambda i: 'blue' if p_color[i] else 'red'
     p = lambda i: [0, 0] if i == -1 else [i + 1, p_number[i]]
     plt = point([0, 0], marker='x', size=100)
     for i in range(d):
         plt += line2d([p(i - 1), p(i)], alpha=.5)
         plt += point(p(i), color=color(i), size=100)
         if p_color[i]:
             [x, y] = p(i)
             plt += text(r"$\alpha_%i$" % (self._i_alpha[p_ev[i]] + 1),
                         [x, y + .2],
                         fontsize=40)
         else:
             [x, y] = p(i)
             plt += text(r"$\beta_%i$" % (self._i_beta[p_ev[i]] + 1),
                         [x, y + .2],
                         fontsize=40)
     plt.show(axes=False, ymin=0, xmin=0, xmax=d)
Example #16
0
 def make_chart(self, region=None):
     G = Graphics()
     smin, smax, nmin, nmax = [], [], [], []
     for d in self.chartgens(region):
         x, y = self.get_coords(d)
         G += point2d((x, y), zorder=10)
         smin.append(y)
         smax.append(y)
         nmin.append(x)
         nmax.append(x)
         smin = [
             min(smin),
         ]
         smax = [
             max(smax),
         ]
         nmin = [
             min(nmin),
         ]
         nmax = [
             max(nmax),
         ]
     for l in self.chartlines():
         try:
             pts, lineargs = self.lineinfo[l["line"]]
             x1, y1 = self.get_coords(self.geninfo(int(l["src"])))
             x2, y2 = self.get_coords(self.geninfo(int(l["tar"])))
             G += line2d([(x1, y1), (x2, y2)], **lineargs)
         except:
             print("line not understood:", l)
     off = 0.5
     G.ymin(smin[0] - off)
     G.ymax(smax[0] + off)
     G.xmin(nmin[0] - off)
     G.xmax(nmax[0] + off)
     return G
Example #17
0
File: iet.py Project: sagemath/sage
    def plot_two_intervals(self,
                           position=(0,0),
                           vertical_alignment='center',
                           horizontal_alignment='left',
                           interval_height=0.1,
                           labels_height=0.05,
                           fontsize=14,
                           labels=True,
                           colors=None):
        r"""
        Returns a picture of the interval exchange transformation.

        INPUT:

        - ``position`` - a 2-uple of the position

        - ``horizontal_alignment`` - left (default), center or right

        - ``labels`` - boolean (default: True)

        - ``fontsize`` - the size of the label


        OUTPUT:

        2d plot -- a plot of the two intervals (domain and range)

        EXAMPLES::

            sage: t = iet.IntervalExchangeTransformation(('a b','b a'),[1,1])
            sage: t.plot_two_intervals()
            Graphics object consisting of 8 graphics primitives
        """
        from sage.plot.all import Graphics
        from sage.plot.line import line2d
        from sage.plot.text import text
        from sage.plot.colors import rainbow

        G = Graphics()

        lengths = [float(_) for _ in self._lengths]
        total_length = sum(lengths)

        if colors is None:
            colors = rainbow(len(self._permutation), 'rgbtuple')

        if horizontal_alignment == 'left':
            s = position[0]
        elif horizontal_alignment == 'center':
            s = position[0] - total_length / 2
        elif horizontal_alignment == 'right':
            s = position[0] - total_length
        else:
            raise ValueError("horizontal_alignement must be left, center or right")

        top_height = position[1] + interval_height
        for i in self._permutation._intervals[0]:
            G += line2d([(s,top_height), (s+lengths[i],top_height)],
                        rgbcolor=colors[i])
            if labels:
                G += text(str(self._permutation._alphabet.unrank(i)),
                          (s+float(lengths[i])/2, top_height+labels_height),
                          horizontal_alignment='center',
                          rgbcolor=colors[i],
                          fontsize=fontsize)

            s += lengths[i]

        if horizontal_alignment == 'left':
            s = position[0]
        elif horizontal_alignment == 'center':
            s = position[0] - total_length / 2
        elif horizontal_alignment == 'right':
            s = position[0] - total_length
        else:
            raise ValueError("horizontal_alignement must be left, center or right")

        bottom_height = position[1] - interval_height
        for i in self._permutation._intervals[1]:
            G += line2d([(s,bottom_height), (s+lengths[i],bottom_height)],
                        rgbcolor=colors[i])
            if labels:
                G += text(str(self._permutation._alphabet.unrank(i)),
                          (s+float(lengths[i])/2, bottom_height-labels_height),
                          horizontal_alignment='center',
                          rgbcolor=colors[i],
                          fontsize=fontsize)
            s += lengths[i]

        return G
Example #18
0
    def plot_two_intervals(self,
                           position=(0, 0),
                           vertical_alignment='center',
                           horizontal_alignment='left',
                           interval_height=0.1,
                           labels_height=0.05,
                           fontsize=14,
                           labels=True,
                           colors=None):
        r"""
        Returns a picture of the interval exchange transformation.

        INPUT:

        - ``position`` - a 2-uple of the position

        - ``horizontal_alignment`` - left (default), center or right

        - ``labels`` - boolean (default: True)

        - ``fontsize`` - the size of the label


        OUTPUT:

        2d plot -- a plot of the two intervals (domain and range)

        EXAMPLES::

            sage: t = iet.IntervalExchangeTransformation(('a b','b a'),[1,1])
            sage: t.plot_two_intervals()
            Graphics object consisting of 8 graphics primitives
        """
        from sage.plot.all import Graphics
        from sage.plot.line import line2d
        from sage.plot.text import text
        from sage.plot.colors import rainbow

        G = Graphics()

        lengths = [float(_) for _ in self._lengths]
        total_length = sum(lengths)

        if colors is None:
            colors = rainbow(len(self._permutation), 'rgbtuple')

        if horizontal_alignment == 'left':
            s = position[0]
        elif horizontal_alignment == 'center':
            s = position[0] - total_length / 2
        elif horizontal_alignment == 'right':
            s = position[0] - total_length
        else:
            raise ValueError(
                "horizontal_alignement must be left, center or right")

        top_height = position[1] + interval_height
        for i in self._permutation._intervals[0]:
            G += line2d([(s, top_height), (s + lengths[i], top_height)],
                        rgbcolor=colors[i])
            if labels:
                G += text(
                    str(self._permutation._alphabet.unrank(i)),
                    (s + float(lengths[i]) / 2, top_height + labels_height),
                    horizontal_alignment='center',
                    rgbcolor=colors[i],
                    fontsize=fontsize)

            s += lengths[i]

        if horizontal_alignment == 'left':
            s = position[0]
        elif horizontal_alignment == 'center':
            s = position[0] - total_length / 2
        elif horizontal_alignment == 'right':
            s = position[0] - total_length
        else:
            raise ValueError(
                "horizontal_alignement must be left, center or right")

        bottom_height = position[1] - interval_height
        for i in self._permutation._intervals[1]:
            G += line2d([(s, bottom_height), (s + lengths[i], bottom_height)],
                        rgbcolor=colors[i])
            if labels:
                G += text(
                    str(self._permutation._alphabet.unrank(i)),
                    (s + float(lengths[i]) / 2, bottom_height - labels_height),
                    horizontal_alignment='center',
                    rgbcolor=colors[i],
                    fontsize=fontsize)
            s += lengths[i]

        return G