Changeset 5348:2f2dec30bb01


Ignore:
Timestamp:
06/16/07 14:32:38 (6 years ago)
Author:
Robert L Miller <rlm@…>
Branch:
default
Message:

made iterations available for plot, show, and print_to_eps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/graphs/graph.py

    r5347 r5348  
    21562156    def plot(self, pos=None, layout=None, vertex_labels=True, edge_labels=False, 
    21572157             vertex_size=200, graph_border=False, color_dict=None, partition=None, 
    2158              edge_colors=None, scaling_term=0.05, xmin=None, xmax=None):  # xmin and xmax are ignored 
     2158             edge_colors=None, scaling_term=0.05, xmin=None, xmax=None, 
     2159             iterations=50):  # xmin and xmax are ignored 
    21592160        """ 
    21602161        Returns a graphics object representing the (di)graph. 
     
    21802181                is too small, decrease. should be positive, but values much bigger than 
    21812182                1/8 won't be useful unless the nodes are huge 
     2183            iterations -- how many iterations of the spring layout algorithm to 
     2184                go through, if applicable 
    21822185         
    21832186        EXAMPLES: 
     
    22492252            pos = None 
    22502253        if pos is None: 
    2251             pos = graph_fast.spring_layout_fast(self) 
     2254            pos = graph_fast.spring_layout_fast(self, iterations=iterations) 
    22522255        else: 
    22532256            for v in pos: 
     
    22682271    def show(self, pos=None, layout=None, vertex_labels=True, edge_labels=False, vertex_size=200, 
    22692272             graph_border=False, color_dict=None, edge_colors=None, partition=None, 
    2270              scaling_term=0.05, talk=False, **kwds): 
     2273             scaling_term=0.05, talk=False, iterations=50, **kwds): 
    22712274        """ 
    22722275        Shows the (di)graph. 
     
    22932296                1/8 won't be useful unless the nodes are huge 
    22942297            talk -- if true, prints large nodes with white backgrounds so that labels are legible on slies 
    2295          
     2298            iterations -- how many iterations of the spring layout algorithm to 
     2299                go through, if applicable 
     2300 
    22962301        EXAMPLES: 
    22972302            sage: from math import sin, cos, pi 
     
    23432348            if partition is None: 
    23442349                color_dict = {'#FFFFFF':self.vertices()} 
    2345         self.plot(pos=pos, layout=layout, vertex_labels=vertex_labels, edge_labels=edge_labels, vertex_size=vertex_size, color_dict=color_dict, edge_colors=edge_colors, graph_border=graph_border, partition=partition, scaling_term=scaling_term).show(**kwds) 
     2350        self.plot(pos=pos, layout=layout, vertex_labels=vertex_labels, edge_labels=edge_labels, vertex_size=vertex_size, color_dict=color_dict, edge_colors=edge_colors, graph_border=graph_border, partition=partition, scaling_term=scaling_term, iterations=iterations).show(**kwds) 
    23462351 
    23472352class Graph(GenericGraph): 
     
    35813586    ### Visualization 
    35823587 
    3583     def write_to_eps(self, filename): 
     3588    def write_to_eps(self, filename, iterations=50): 
    35843589        """ 
    35853590        Writes a plot of the graph to filename in eps format. 
    35863591         
    35873592        It is relatively simple to include this file in a latex document: 
     3593         
     3594        INPUT: 
     3595            filename 
     3596            iterations -- how many iterations of the spring layout algorithm to 
     3597                go through, if applicable 
    35883598         
    35893599        \usepackage{graphics} must appear before the beginning of the document, 
     
    35983608        from sage.graphs.print_graphs import print_graph_eps 
    35993609        if self._pos is None: 
    3600             pos = graph_fast.spring_layout_fast(self) 
     3610            pos = graph_fast.spring_layout_fast(self, iterations=iterations) 
    36013611        else: 
    36023612            pos = self._pos 
     
    36043614            for v in self.vertices(): 
    36053615                if v not in keys: 
    3606                     pos = graph_fast.spring_layout_fast(self) 
     3616                    pos = graph_fast.spring_layout_fast(self, iterations=iterations) 
    36073617                    break 
    36083618        xmin = 0.0 
     
    36323642               vertex_color=(1,0,0), vertex_size=0.06, 
    36333643               edge_color=(0,0,0), edge_size=0.02, 
    3634                pos3d=None, **kwds): 
     3644               pos3d=None, iterations=50, **kwds): 
    36353645        """ 
    36363646        Plots the graph using Tachyon, and returns a Tachyon object containing 
     
    36443654            edge_size -- float (default: 0.02) 
    36453655            pos3d -- a position dictionary for the vertices 
     3656            iterations -- how many iterations of the spring layout algorithm to 
     3657                go through, if applicable 
    36463658            **kwds -- passed on to the Tachyon command 
    36473659         
     
    36593671        """ 
    36603672        TT, pos3d = tachyon_vertex_plot(self, bgcolor=bgcolor, vertex_color=vertex_color, 
    3661                                         vertex_size=vertex_size, pos3d=pos3d, **kwds) 
     3673                                        vertex_size=vertex_size, pos3d=pos3d, iterations=iterations, **kwds) 
    36623674        TT.texture('edge', ambient=0.1, diffuse=0.9, specular=0.03, opacity=1.0, color=edge_color) 
    36633675        for u,v,l in self.edges(): 
     
    36693681               vertex_color=(1,0,0), vertex_size=0.06, 
    36703682               edge_color=(0,0,0), edge_size=0.02, 
    3671                pos3d=None, **kwds): 
     3683               pos3d=None, iterations=50, **kwds): 
    36723684        """ 
    36733685        Plots the graph using Tachyon, and shows the resulting plot. 
     
    36813693            pos3d -- a position dictionary for the vertices 
    36823694            (pos3d -- currently ignored, pending GSL random point distribution in sphere...) 
     3695            iterations -- how many iterations of the spring layout algorithm to 
     3696                go through, if applicable 
    36833697         
    36843698        EXAMPLES: 
     
    36943708 
    36953709        """ 
    3696         self.plot3d(bgcolor=bgcolor, vertex_color=vertex_color, edge_color=edge_color, vertex_size=vertex_size, edge_size=edge_size).show(**kwds) 
     3710        self.plot3d(bgcolor=bgcolor, vertex_color=vertex_color, edge_color=edge_color, vertex_size=vertex_size, edge_size=edge_size, iterations=iterations).show(**kwds) 
    36973711     
    36983712    ### Connected components 
     
    52955309                        vertex_color=(1,0,0), 
    52965310                        vertex_size=0.06, 
    5297                         pos3d=None, **kwds): 
     5311                        pos3d=None, 
     5312                        iterations=50, **kwds): 
    52985313    import networkx 
    52995314    from math import sqrt 
     
    53045319    spring = False 
    53055320    if pos3d is None: 
    5306         pos3d = graph_fast.spring_layout_fast(g, dim=3) 
     5321        pos3d = graph_fast.spring_layout_fast(g, dim=3, iterations=iterations) 
    53075322    try: 
    53085323        for v in verts: 
Note: See TracChangeset for help on using the changeset viewer.