Tag Info

Hot answers tagged

7

The problem is that the vertices get numbered by their order of appearance in the graph. This means that what you called vertex "6" is actually considered vertex "5". To see what I mean try the following command: VertexList[g] To set the vertices in the desired order, they should be explicitly listed before the edges: g = Graph[Table[i,{i,1,11}],{1 -> ...


6

Note: The following needs a properly color quantized image as input. Color quantization for general images is a problem on its own that depends on many factors and is not addressed below. First we will go step by step, then wrapping up all of it in a function: Import some discrete-colored image: ii = Import["http://i.stack.imgur.com/9vdgV.png"] Then ...


5

I have used the functions EdgeDelete and EdgeAdd to expand the graph. The code generates new vertex names by incrementing the largest vertex name in the graph. nextVertexNames[g_] := Max[VertexList[g]] + {{1, 2, 3}, {4, 5, 6}} replaceTripod[g_, v_] := Module[{ oldNeighbors = DeleteCases[VertexComponent[g, v, 1], v], newNeighbors = nextVertexNames[g], ...


5

You can add additional graphics (arrow) using Epilog or Prolog: Ex1: HighlightGraph[g, path, Epilog -> {Red, Thickness[.01], Arrowheads[.05], Arrow /@ Partition[GraphEmbedding[g][[path]], 2, 1]}] Ex2: HighlightGraph[g, PathGraph[path], Prolog -> {Orange, Thickness[.005], Arrowheads[Table[.04, 10]], ...


4

This is a V9 answer: g = DirectedGraph[GraphData["DodecahedralGraph"], VertexLabels -> "Name", EdgeStyle -> White]; HighlightGraph[g, FindHamiltonianCycle[g][[1]] // Most] g = DirectedGraph[GraphData["DodecahedralGraph"], VertexLabels -> "Name"]; HighlightGraph[g, FindHamiltonianCycle[g][[1]] // Most]


4

GraphDistance[g, 1, 6] returns 3. I've had this problem in the past, and if you want to fix your original method, you can use Sjoerd C. de Vries's answer there. It's one of the few really annoying behaviours of Mathematica I've come across. Example with a shuffled list of vertices, eleven vertices and ten edges: edges = UndirectedEdge @@@ ...


4

Another trick you can do: Graph[Join[Table[1 -> 2, {10}], Table[2 -> 3, {5}], Table[3 -> 1, {5}]], EdgeShapeFunction -> {1 \[DirectedEdge] 2 -> (a = 0; {a++; ColorData[35, "ColorList"][[a]], Arrow[#]} &), 2 \[DirectedEdge] 3 -> (b = 0; {b++; ColorData[55, "ColorList"][[b]], Arrow[#]} &), 3 ...


4

The information concerning SetProperty and PropertyValue timings aren't the full story! The SetProperty invokes no persistent side-effect (one must assign with it to keep the edited graph!) where as PropertyValue does edit the object (in-place). Given that this performance testing is to create an graph object one wants to do more with I'm going to present ...


3

If I understand your question correctly, you want the thickness of the edge to depend on the vertex the edge is directed towards? If so, then you will need to use EdgeShapeFunction: data = {{0, 1, 0}, {0, 0, 2}, {3, 0, 0}}; AdjacencyGraph[data, VertexLabels -> "Name", EdgeShapeFunction -> ({ Thickness[Last[#2]*0.01], ...


2

Taking into account the new information from your edit, I propose the following: Function to produce the edge labels according to multiplicity indicated in the adjacency matrix. edgeLbl[multipliciy_] := Style[StringJoin @ ConstantArray["+", multipliciy], Background -> White] Function to style the edges according to multiplicity. ...


2

The trick is to render both a directed and an undirected edge with the same arrow EdgeShapeFunction. Alas, the full graph representation will retain the different classes of edge, so functions such as FindKClan, VertexOutDegree, VertexInDegree, and others that distinguish between different classes of edge will give incorrect answers. Graph[{1, 2}, ...


2

g = Graph[{1 <-> 2, 2 <-> 3, 3 <->1}]; init = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates]; (* Rescale to 10% padding *) xyScale = 1.1 # -.1 Mean@# &/@ (Through[{Min,Max}[#]] &/@ Transpose@init); Manipulate[SetProperty[g, {VertexCoordinates -> pt, PlotRange -> xyScale}], {{pt, init}, Locator}]


1

This has to be a bug. I think Graph never really associates EdgeWeight with corresponding edges. Here is a simplified example. g = Graph[{1, 2, 3}, { Property[1 <-> 2, EdgeWeight -> x], 1 <-> 3, Property[2 <-> 3, EdgeWeight -> y] }]; gNew = RemoveProperty[{g, ...


1

It just got even more interesting. I tried assigning a list to a VertexWeight and couldn't. I could however assign an EmpiricalDistribution (which is odd as it has a lot of structure inside it). Check this the following timings though: Clear[g] g = CycleGraph[1000]; Timing@Do[ PropertyValue[{g, v}, VertexWeight] = EmpiricalDistribution[RandomReal[{0, ...


1

I have a method to achieve what you want but the procedure is very dirty: We will make two graphs and then Overlay them. The first one is as shown below:- << Combinatorica`; g = MakeGraph[ Subsets[Range[3]], ((Intersection[#2, #1] == #1) && (#1 != #2)) &, VertexLabel -> True]; hdg = HasseDiagram[g]; sgX = ShowGraph[ ...


1

I think the minimal solution to your specific question is: TreeGraph[{1 -> 2, 1 -> 3}, VertexLabels -> {1 -> "a", "b"}] or Graph[{1 -> 2, 1 -> 3}, VertexLabels -> {1 -> "a", "b"}]


1

You could add button to copy or print coordinates: Labeled[Manipulate[ Graphics[{Line[v]}, PlotRange -> {-6, 6}], {{v, {{-5, 5}, {5, 5}, {5, -5}, {-5, -5}}}, Locator, LocatorAutoCreate -> True}, Button["Copy Coordinate", CopyToClipboard[v]], Button["Print Coordinate", Print[v]]], "Locator Example"]


1

This may or may not do what you want. I don't know about making the layout nice, I'm afraid. The function newvertex returns n names which are not used as a vertex in the graph. Then expandVertex takes a vertex name and expands about that vertex in the manner stated. Alternatively, supply a list of names to have the expansion done on each in turn, or supply ...



Only top voted, non community-wiki answers of a minimum length are eligible