Changeset 5710:20c50f991598
- Timestamp:
- 08/12/07 12:01:55 (6 years ago)
- Branch:
- default
- Location:
- sage
- Files:
-
- 2 edited
-
graphs/graph.py (modified) (13 diffs)
-
groups/group.pyx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sage/graphs/graph.py
r5709 r5710 24 24 -- Emily Kirkman (2007-07-21): Genus (including circular planar, all 25 25 embeddings and all planar embeddings), all paths, interior paths 26 -- Bobby Moretti (2007-08-12): fixed up plotting of graphs with 27 edge colors differentiated by label 26 28 27 29 TUTORIAL: … … 2163 2165 2164 2166 ### Visualization 2167 def _color_by_label(self, format='hex'): 2168 """ 2169 Logic for coloring by label (factored out from plot() for use 2170 in 3d plots, etc) 2171 """ 2172 from sage.plot.plot import rainbow 2173 edge_labels = [] 2174 if self.is_directed(): 2175 iterator = self.arc_iterator 2176 else: 2177 iterator = self.edge_iterator 2178 for e in iterator(): 2179 i = 0 2180 while i < len(edge_labels): 2181 if not edge_labels[i][0][2] == e[2]: 2182 i += 1 2183 else: 2184 edge_labels[i].append(e) 2185 break 2186 if i == len(edge_labels): 2187 edge_labels.append([e]) 2188 num_labels = len(edge_labels) 2189 r = rainbow(num_labels, format=format) 2190 edge_colors = {} 2191 for i in range(num_labels): 2192 edge_colors[r[i]] = edge_labels[i] 2193 return edge_colors 2165 2194 2166 2195 def plot(self, pos=None, layout=None, vertex_labels=True,\ … … 2243 2272 2244 2273 """ 2245 from sage.plot.plot import networkx_plot , rainbow2274 from sage.plot.plot import networkx_plot 2246 2275 import networkx 2247 2276 if vertex_colors is None: … … 2295 2324 2296 2325 if color_by_label: 2297 edge_labels = [] 2298 if self.is_directed(): 2299 iterator = self.arc_iterator 2300 else: 2301 iterator = self.edge_iterator 2302 for e in iterator(): 2303 i = 0 2304 while i < len(edge_labels): 2305 if not edge_labels[i][0][2] == e[2]: 2306 i += 1 2307 else: 2308 edge_labels[i].append(e) 2309 break 2310 if i == len(edge_labels): 2311 edge_labels.append([e]) 2312 num_labels = len(edge_labels) 2313 R = rainbow(num_labels) 2314 edge_colors = {} 2315 for i in range(num_labels): 2316 edge_colors[R[i]] = edge_labels[i] 2317 2326 edge_colors = self._color_by_label() 2327 2318 2328 G = networkx_plot(self._nxg, pos=pos, vertex_labels=vertex_labels, vertex_size=vertex_size, vertex_colors=vertex_colors, edge_colors=edge_colors, graph_border=graph_border, scaling_term=scaling_term) 2319 2329 if edge_labels: … … 3988 3998 vertex_colors=None, vertex_size=0.06, 3989 3999 edge_colors=None, edge_size=0.02, 3990 pos3d=None, iterations=50, **kwds):4000 pos3d=None, iterations=50, color_by_label=False, **kwds): 3991 4001 """ 3992 4002 Plots the graph using Tachyon, and returns a Tachyon object containing … … 4030 4040 vertex_size=vertex_size, pos3d=pos3d, iterations=iterations, **kwds) 4031 4041 edges = self.edges() 4042 4043 if color_by_label: 4044 if edge_colors is None: 4045 # do the coloring 4046 edge_colors = self._color_by_label(format='rgbtuple') 4047 4032 4048 if edge_colors is None: 4033 4049 edge_colors = { (0,0,0) : edges } 4034 4050 4035 4051 i = 0 4052 4036 4053 for color in edge_colors: 4037 4054 i += 1 … … 4039 4056 for u, v, l in edge_colors[color]: 4040 4057 TT.fcylinder( (pos3d[u][0],pos3d[u][1],pos3d[u][2]), (pos3d[v][0],pos3d[v][1],pos3d[v][2]), edge_size,'edge_color_%d'%i) 4058 4041 4059 return TT 4042 4060 … … 4044 4062 vertex_colors=None, vertex_size=0.06, 4045 4063 edge_colors=None, edge_size=0.02, 4046 pos3d=None, iterations=50, **kwds):4064 pos3d=None, iterations=50, color_by_label=False, **kwds): 4047 4065 """ 4048 4066 Plots the graph using Tachyon, and shows the resulting plot. … … 4082 4100 4083 4101 """ 4084 self.plot3d(bgcolor=bgcolor, vertex_colors=vertex_colors, edge_colors=edge_colors, vertex_size=vertex_size, edge_size=edge_size, iterations=iterations).show(**kwds) 4102 self.plot3d(bgcolor=bgcolor, vertex_colors=vertex_colors, 4103 edge_colors=edge_colors, vertex_size=vertex_size, 4104 edge_size=edge_size, iterations=iterations, 4105 color_by_label=color_by_label).show(**kwds) 4085 4106 4086 4107 ### Connected components … … 5310 5331 arc_size=0.02, 5311 5332 arc_size2=0.0325, 5312 arc_colors=None, pos3d=None, **kwds): 5333 arc_colors=None, pos3d=None, 5334 color_by_label=False, **kwds): 5313 5335 """ 5314 5336 Plots the graph using Tachyon, and returns a Tachyon object containing … … 5353 5375 vertex_size=vertex_size, pos3d=pos3d, **kwds) 5354 5376 arcs = self.arcs() 5377 i = 0 5378 5379 if color_by_label: 5380 if arc_colors is None: 5381 arc_colors = self._color_by_label(format='rgbtuple') 5382 5355 5383 if arc_colors is None: 5356 5384 arc_colors = { (0,0,0) : arcs } 5357 5385 5358 i = 05359 5386 for color in arc_colors: 5360 5387 i += 1 … … 5373 5400 arc_size=0.02, 5374 5401 arc_size2=0.0325, 5375 arc_colors=None, pos3d=None, **kwds): 5402 arc_colors=None, 5403 pos3d=None, color_by_label=False, **kwds): 5376 5404 """ 5377 5405 Plots the graph using Tachyon, and shows the resulting plot. … … 5412 5440 5413 5441 """ 5414 self.plot3d(bgcolor=bgcolor, vertex_colors=vertex_colors, vertex_size=vertex_size, arc_size=arc_size, arc_size2=arc_size2, arc_colors=arc_colors, **kwds).show() 5442 5443 self.plot3d(bgcolor=bgcolor, vertex_colors=vertex_colors, 5444 vertex_size=vertex_size, arc_size=arc_size, 5445 arc_size2=arc_size2, arc_colors=arc_colors, 5446 color_by_label=color_by_label, **kwds).show() 5415 5447 5416 5448 ### Connected components -
sage/groups/group.pyx
r5708 r5710 128 128 return True 129 129 130 def cayley_graph(self , label=False):130 def cayley_graph(self): 131 131 """ 132 Computes the cayley graph 132 Returns the cayley graph for this finite group, as a SAGE 133 DiGraph object. To plot the graph with with different colors 134 135 EXAMPLES: 136 sage: D4 = DihedralGroup(4); D4 137 Dihedral group of order 8 as a permutation group 138 sage: show(D4.cayley_graph(), color_by_label=True, edge_labels=True) 139 140 sage: A5 = AlternatingGroup(5); A5 141 Alternating group of order 5!/2 as a permutation group 142 sage: G = A5.cayley_graph() 143 sage: G.show3d(color_by_label=True, arc_size=0.01, arc_size2=0.02, vertex_size=0.03) 144 sage: G.show3d(vertex_size=0.03, arc_size=0.01, arc_size2=0.02, vertex_colors={(1,1,1):x.vertices()}, bgcolor=(0,0,0), color_by_label=True, xres=700, yres=700, iterations=200) # long time 145 146 AUTHOR: 147 -- (2007-08-10) Bobby Moretti 133 148 """ 134 149 from sage.graphs.graph import DiGraph
Note: See TracChangeset
for help on using the changeset viewer.
