Changeset 5348:2f2dec30bb01
- Timestamp:
- 06/16/07 14:32:38 (6 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/graphs/graph.py (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/graphs/graph.py
r5347 r5348 2156 2156 def plot(self, pos=None, layout=None, vertex_labels=True, edge_labels=False, 2157 2157 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 2159 2160 """ 2160 2161 Returns a graphics object representing the (di)graph. … … 2180 2181 is too small, decrease. should be positive, but values much bigger than 2181 2182 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 2182 2185 2183 2186 EXAMPLES: … … 2249 2252 pos = None 2250 2253 if pos is None: 2251 pos = graph_fast.spring_layout_fast(self )2254 pos = graph_fast.spring_layout_fast(self, iterations=iterations) 2252 2255 else: 2253 2256 for v in pos: … … 2268 2271 def show(self, pos=None, layout=None, vertex_labels=True, edge_labels=False, vertex_size=200, 2269 2272 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): 2271 2274 """ 2272 2275 Shows the (di)graph. … … 2293 2296 1/8 won't be useful unless the nodes are huge 2294 2297 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 2296 2301 EXAMPLES: 2297 2302 sage: from math import sin, cos, pi … … 2343 2348 if partition is None: 2344 2349 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) 2346 2351 2347 2352 class Graph(GenericGraph): … … 3581 3586 ### Visualization 3582 3587 3583 def write_to_eps(self, filename ):3588 def write_to_eps(self, filename, iterations=50): 3584 3589 """ 3585 3590 Writes a plot of the graph to filename in eps format. 3586 3591 3587 3592 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 3588 3598 3589 3599 \usepackage{graphics} must appear before the beginning of the document, … … 3598 3608 from sage.graphs.print_graphs import print_graph_eps 3599 3609 if self._pos is None: 3600 pos = graph_fast.spring_layout_fast(self )3610 pos = graph_fast.spring_layout_fast(self, iterations=iterations) 3601 3611 else: 3602 3612 pos = self._pos … … 3604 3614 for v in self.vertices(): 3605 3615 if v not in keys: 3606 pos = graph_fast.spring_layout_fast(self )3616 pos = graph_fast.spring_layout_fast(self, iterations=iterations) 3607 3617 break 3608 3618 xmin = 0.0 … … 3632 3642 vertex_color=(1,0,0), vertex_size=0.06, 3633 3643 edge_color=(0,0,0), edge_size=0.02, 3634 pos3d=None, **kwds):3644 pos3d=None, iterations=50, **kwds): 3635 3645 """ 3636 3646 Plots the graph using Tachyon, and returns a Tachyon object containing … … 3644 3654 edge_size -- float (default: 0.02) 3645 3655 pos3d -- a position dictionary for the vertices 3656 iterations -- how many iterations of the spring layout algorithm to 3657 go through, if applicable 3646 3658 **kwds -- passed on to the Tachyon command 3647 3659 … … 3659 3671 """ 3660 3672 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) 3662 3674 TT.texture('edge', ambient=0.1, diffuse=0.9, specular=0.03, opacity=1.0, color=edge_color) 3663 3675 for u,v,l in self.edges(): … … 3669 3681 vertex_color=(1,0,0), vertex_size=0.06, 3670 3682 edge_color=(0,0,0), edge_size=0.02, 3671 pos3d=None, **kwds):3683 pos3d=None, iterations=50, **kwds): 3672 3684 """ 3673 3685 Plots the graph using Tachyon, and shows the resulting plot. … … 3681 3693 pos3d -- a position dictionary for the vertices 3682 3694 (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 3683 3697 3684 3698 EXAMPLES: … … 3694 3708 3695 3709 """ 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) 3697 3711 3698 3712 ### Connected components … … 5295 5309 vertex_color=(1,0,0), 5296 5310 vertex_size=0.06, 5297 pos3d=None, **kwds): 5311 pos3d=None, 5312 iterations=50, **kwds): 5298 5313 import networkx 5299 5314 from math import sqrt … … 5304 5319 spring = False 5305 5320 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) 5307 5322 try: 5308 5323 for v in verts:
Note: See TracChangeset
for help on using the changeset viewer.
