Ticket #14640: trac_14640_refactor_plot_expose.patch

File trac_14640_refactor_plot_expose.patch, 12.7 KB (added by vbraun, 6 years ago)

Initial patch

  • sage/combinat/root_system/plot.py

    # HG changeset patch
    # User Volker Braun <vbraun.name@gmail.com>
    # Date 1369481087 -3600
    # Node ID d064554bec8a93c12b8b164f53aafa4c68860dc9
    # Parent  16768eaa774a10ee080f972ed1a80ab32baeaad9
    Refactor the plot_exposed() function into a method of plot objects
    
    diff --git a/sage/combinat/root_system/plot.py b/sage/combinat/root_system/plot.py
    a b  
    10891089
    10901090        TESTS::
    10911091
    1092             sage: from sage.combinat.root_system.plot import plot_expose
    1093             sage: plot_expose(H)
     1092            sage: H.describe()
     1093            Text '$H_{\alpha^\vee_{1}}$' at the point (0.0,3.15)
    10941094            Line defined by 2 points: [(0.0, 3.0), (0.0, -3.0)]
    1095             Text '$H_{\alpha^\vee_{1}}$' at the point (0.0,3.15)
    10961095
    10971096        ::
    10981097
     
    11391138        return self.cone(lines = basis, color = self.color(label), label=text_label,
    11401139                         as_polyhedron=as_polyhedron)
    11411140
    1142 def plot_expose(graphic_object):
    1143     r"""
    1144     Print some data on a 2D graphic objects for testing purposes.
    1145 
    1146     EXAMPLES::
    1147 
    1148         sage: from sage.combinat.root_system.plot import plot_expose
    1149         sage: plot_expose(polytopes.n_cube(2).plot())
    1150         Point set defined by 4 point(s): [(-1.0, -1.0), (-1.0, 1.0), (1.0, -1.0), (1.0, 1.0)]
    1151         Line defined by 2 points: [(-1.0, -1.0), (-1.0, 1.0)]
    1152         Line defined by 2 points: [(-1.0, -1.0), (1.0, -1.0)]
    1153         Line defined by 2 points: [(-1.0, 1.0), (1.0, 1.0)]
    1154         Line defined by 2 points: [(1.0, -1.0), (1.0, 1.0)]
    1155         Polygon defined by 4 points: [(1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), (1.0, -1.0)]
    1156     """
    1157     for g in graphic_object:
    1158         if hasattr(g, "xdata"):
    1159             print "%s:\t%s"%(g, zip(g.xdata, g.ydata))
    1160         else:
    1161             print g
    1162 
    11631141
    11641142@cached_function
    11651143def barycentric_projection_matrix(n, angle=0):
  • sage/combinat/root_system/root_lattice_realizations.py

    diff --git a/sage/combinat/root_system/root_lattice_realizations.py b/sage/combinat/root_system/root_lattice_realizations.py
    a b  
    20032003
    20042004            TESTS::
    20052005
    2006                 sage: from sage.combinat.root_system.plot import plot_expose
    20072006                sage: L = RootSystem(["A",2]).ambient_space()
    2008                 sage: plot_expose(L.plot_reflection_hyperplanes())
     2007                sage: L.plot_reflection_hyperplanes().describe()
     2008                Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15)
     2009                Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15)
    20092010                Line defined by 2 points: [(-1.73..., 3.0), (1.73..., -3.0)]
     2011                Line defined by 2 points: [(1.73..., 3.0), (-1.73..., -3.0)]
     2012
     2013                sage: L.plot_reflection_hyperplanes("all").describe()
     2014                Text '$H_{\alpha^\vee_{1} + \alpha^\vee_{2}}$' at the point (3.15,0.0)
    20102015                Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15)
     2016                Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15)
     2017                Line defined by 2 points: [(-1.73..., 3.0), (1.73..., -3.0)]
    20112018                Line defined by 2 points: [(1.73..., 3.0), (-1.73..., -3.0)]
     2019                Line defined by 2 points: [(3.0, 0.0), (-3.0, 0.0)]
     2020
     2021                sage: L = RootSystem(["A",2,1]).ambient_space()
     2022                sage: L.plot_reflection_hyperplanes().describe()
     2023                Text '$H_{\alpha^\vee_{0}}$' at the point (3.15,0.90...)
     2024                Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15)
    20122025                Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15)
    2013 
    2014                 sage: plot_expose(L.plot_reflection_hyperplanes("all"))
    20152026                Line defined by 2 points: [(-1.73..., 3.0), (1.73..., -3.0)]
    2016                 Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15)
    20172027                Line defined by 2 points: [(1.73..., 3.0), (-1.73..., -3.0)]
    2018                 Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15)
    2019                 Line defined by 2 points: [(3.0, 0.0), (-3.0, 0.0)]
    2020                 Text '$H_{\alpha^\vee_{1} + \alpha^\vee_{2}}$' at the point (3.15,0.0)
    2021 
    2022                 sage: L = RootSystem(["A",2,1]).ambient_space()
    2023                 sage: plot_expose(L.plot_reflection_hyperplanes())
    20242028                Line defined by 2 points: [(3.0, 0.86...), (-3.0, 0.86...)]
    2025                 Text '$H_{\alpha^\vee_{0}}$' at the point (3.15,0.90...)
    2026                 Line defined by 2 points: [(-1.73..., 3.0), (1.73..., -3.0)]
    2027                 Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15)
    2028                 Line defined by 2 points: [(1.73..., 3.0), (-1.73..., -3.0)]
    2029                 Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15)
    20302029
    20312030            .. TODO:: Provide an option for transparency?
    20322031            """
     
    20822081
    20832082            TESTS::
    20842083
    2085                 sage: from sage.combinat.root_system.plot import plot_expose
    20862084                sage: L = RootSystem(["B",2]).ambient_space()
    2087                 sage: plot_expose(L.plot_hedron())
     2085                sage: L.plot_hedron().describe()
     2086                Polygon defined by 8 points: [(1.5, 0.5), (0.5, 1.5), (-0.5, 1.5), (-1.5, 0.5), (-1.5, -0.5), (-0.5, -1.5), (0.5, -1.5), (1.5, -0.5)]
     2087                Line defined by 2 points: [(-0.5, -1.5), (0.5, -1.5)]
     2088                Line defined by 2 points: [(-0.5, 1.5), (0.5, 1.5)]
     2089                Line defined by 2 points: [(-1.5, -0.5), (-0.5, -1.5)]
     2090                Line defined by 2 points: [(-1.5, -0.5), (-1.5, 0.5)]
     2091                Line defined by 2 points: [(-1.5, 0.5), (-0.5, 1.5)]
     2092                Line defined by 2 points: [(0.5, -1.5), (1.5, -0.5)]
     2093                Line defined by 2 points: [(0.5, 1.5), (1.5, 0.5)]
     2094                Line defined by 2 points: [(1.5, -0.5), (1.5, 0.5)]
    20882095                Point set defined by 8 point(s): [(-1.5, -0.5), (-1.5, 0.5), (-0.5, -1.5), (-0.5, 1.5), (0.5, -1.5), (0.5, 1.5), (1.5, -0.5), (1.5, 0.5)]
    2089                 Line defined by 2 points:        [(-1.5, -0.5), (-1.5, 0.5)]
    2090                 Line defined by 2 points:        [(-1.5, -0.5), (-0.5, -1.5)]
    2091                 Line defined by 2 points:        [(-1.5, 0.5), (-0.5, 1.5)]
    2092                 Line defined by 2 points:        [(-0.5, -1.5), (0.5, -1.5)]
    2093                 Line defined by 2 points:        [(-0.5, 1.5), (0.5, 1.5)]
    2094                 Line defined by 2 points:        [(0.5, -1.5), (1.5, -0.5)]
    2095                 Line defined by 2 points:        [(0.5, 1.5), (1.5, 0.5)]
    2096                 Line defined by 2 points:        [(1.5, -0.5), (1.5, 0.5)]
    2097                 Polygon defined by 8 points:     [(1.5, 0.5), (0.5, 1.5), (-0.5, 1.5), (-1.5, 0.5), (-1.5, -0.5), (-0.5, -1.5), (0.5, -1.5), (1.5, -0.5)]
    20982096            """
    20992097            from sage.geometry.polyhedron.all import Polyhedron
    21002098            plot_options = self.plot_parse_options(**options)
     
    21412139
    21422140            TESTS::
    21432141
    2144                 sage: from sage.combinat.root_system.plot import plot_expose
    21452142                sage: L = RootSystem(["B",2,1]).ambient_space()
    2146                 sage: plot_expose(L.plot_fundamental_chamber())
     2143                sage: L.plot_fundamental_chamber().describe()
    21472144                Polygon defined by 3 points:     [(0.5, 0.5), (1.0, 0.0), (0.0, 0.0)]
    21482145
    2149                 sage: plot_expose(L.plot_fundamental_chamber(style="classical"))
     2146                sage: L.plot_fundamental_chamber(style="classical").describe()
    21502147                Polygon defined by 3 points:     [(0.0, 0.0), (3.0, 3.0), (3.0, 0.0)]
    21512148            """
    21522149            plot_options = self.plot_parse_options(**options)
     
    22062203
    22072204            TESTS::
    22082205
    2209                 sage: from sage.combinat.root_system.plot import plot_expose
    22102206                sage: L = RootSystem(["A",2,1]).weight_space()
    2211                 sage: plot_expose(L.plot_alcoves(alcoves=[[0,0]]))
     2207                sage: L.plot_alcoves(alcoves=[[0,0]]).describe()
     2208                Line defined by 2 points: [(-1.0, 0.0), (0.0, -1.0)]
     2209                Line defined by 2 points: [(-1.0, 1.0), (-1.0, 0.0)]
     2210                Line defined by 2 points: [(-1.0, 1.0), (0.0, 0.0)]
     2211                Line defined by 2 points: [(0.0, 0.0), (-1.0, 0.0)]
     2212                Line defined by 2 points: [(0.0, 0.0), (0.0, -1.0)]
     2213                Line defined by 2 points: [(0.0, 0.0), (1.0, -1.0)]
     2214                Line defined by 2 points: [(0.0, 1.0), (-1.0, 1.0)]
     2215                Line defined by 2 points: [(0.0, 1.0), (0.0, 0.0)]
    22122216                Line defined by 2 points: [(0.0, 1.0), (1.0, 0.0)]
    2213                 Line defined by 2 points: [(0.0, 1.0), (0.0, 0.0)]
     2217                Line defined by 2 points: [(1.0, -1.0), (0.0, -1.0)]
    22142218                Line defined by 2 points: [(1.0, 0.0), (0.0, 0.0)]
    2215                 Line defined by 2 points: [(0.0, 1.0), (-1.0, 1.0)]
    2216                 Line defined by 2 points: [(-1.0, 1.0), (0.0, 0.0)]
    2217                 Line defined by 2 points: [(-1.0, 1.0), (-1.0, 0.0)]
    2218                 Line defined by 2 points: [(0.0, 0.0), (-1.0, 0.0)]
    2219                 Line defined by 2 points: [(-1.0, 0.0), (0.0, -1.0)]
    22202219                Line defined by 2 points: [(1.0, 0.0), (1.0, -1.0)]
    2221                 Line defined by 2 points: [(0.0, 0.0), (1.0, -1.0)]
    2222                 Line defined by 2 points: [(1.0, -1.0), (0.0, -1.0)]
    2223                 Line defined by 2 points: [(0.0, 0.0), (0.0, -1.0)]
    22242220            """
    22252221            plot_options = self.plot_parse_options(**options)
    22262222            if not hasattr(self, "fundamental_weights"):
     
    24252421
    24262422            TESTS::
    24272423
    2428                 sage: from sage.combinat.root_system.plot import plot_expose
    24292424                sage: L = RootSystem(["A",2,1]).weight_space()
    24302425                sage: p = L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1],
    24312426                ...                          foldings = [False, False, True, False, False, False, True, False, True, False],
    24322427                ...                          color="green",
    24332428                ...                          start=L.rho())
    2434                 sage: plot_expose(p)
     2429                sage: p.describe()
     2430                Line defined by 2 points: [(-1.0, 8.0), (-1.5, 9.0)]
     2431                Line defined by 2 points: [(1.0, 4.0), (1.5, 4.5)]
     2432                Line defined by 2 points: [(1.0, 7.0), (1.5, 6.0)]
     2433                Arrow from (-1.0,5.0) to (-2.0,7.0)
     2434                Arrow from (-1.0,8.0) to (1.0,7.0)
     2435                Arrow from (-1.5,9.0) to (-1.0,8.0)
     2436                Arrow from (-2.0,7.0) to (-1.0,8.0)
    24352437                Arrow from (1.0,1.0) to (2.0,2.0)
     2438                Arrow from (1.0,4.0) to (-1.0,5.0)
     2439                Arrow from (1.0,7.0) to (2.0,8.0)
     2440                Arrow from (1.5,4.5) to (1.0,4.0)
     2441                Arrow from (1.5,6.0) to (1.0,7.0)
    24362442                Arrow from (2.0,2.0) to (1.0,4.0)
    2437                 Line defined by 2 points: [(1.0, 4.0), (1.5, 4.5)]
    2438                 Arrow from (1.5,4.5) to (1.0,4.0)
    2439                 Arrow from (1.0,4.0) to (-1.0,5.0)
    2440                 Arrow from (-1.0,5.0) to (-2.0,7.0)
    2441                 Arrow from (-2.0,7.0) to (-1.0,8.0)
    2442                 Line defined by 2 points: [(-1.0, 8.0), (-1.5, 9.0)]
    2443                 Arrow from (-1.5,9.0) to (-1.0,8.0)
    2444                 Arrow from (-1.0,8.0) to (1.0,7.0)
    2445                 Line defined by 2 points: [(1.0, 7.0), (1.5, 6.0)]
    2446                 Arrow from (1.5,6.0) to (1.0,7.0)
    2447                 Arrow from (1.0,7.0) to (2.0,8.0)
    24482443            """
    24492444            from sage.plot.line import line
    24502445            from sage.plot.arrow import arrow
  • sage/plot/graphics.py

    diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
    a b  
    26882688                figure.savefig(filename, dpi=dpi,
    26892689                           transparent=transparent)
    26902690
     2691    def describe(self):
     2692        r"""
     2693        Print a textual description to stdout.
     2694
     2695        This method is mostly used for doctests.
     2696   
     2697        EXAMPLES::
     2698   
     2699            sage: polytopes.n_cube(2).plot().describe()
     2700            Polygon defined by 4 points: [(1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), (1.0, -1.0)]
     2701            Line defined by 2 points: [(-1.0, -1.0), (-1.0, 1.0)]
     2702            Line defined by 2 points: [(-1.0, -1.0), (1.0, -1.0)]
     2703            Line defined by 2 points: [(-1.0, 1.0), (1.0, 1.0)]
     2704            Line defined by 2 points: [(1.0, -1.0), (1.0, 1.0)]
     2705            Point set defined by 4 point(s): [(-1.0, -1.0), (-1.0, 1.0), (1.0, -1.0), (1.0, 1.0)]
     2706        """
     2707        data = []
     2708        for g in self:
     2709            g_zorder = g.options().get('zorder', 0)
     2710            if hasattr(g, 'xdata'):
     2711                g_str = '{0}:\t{1}'.format(g, zip(g.xdata, g.ydata))
     2712            else:
     2713                g_str = repr(g)
     2714            data.append([g_zorder, g_str, g])
     2715        data.sort()
     2716        for g in data:
     2717            print g[1]
     2718   
    26912719
    26922720class GraphicsArray(SageObject):
    26932721    """