New answers tagged

5

M and U in your example are matrices, not graphs. You can use AdjacencyGraph to create a graph from them. The output of GraphPlot is a Graphics expression, not a Graph expression. We use the term "graph expression" to denote the data structure that Mathematica uses to represent graphs. A graph expression will always have Head Graph. GraphQ[g] returns ...


3

Here's the function you can get (recover) coordinates from rules which define Sierpinski Sieve graph. Code is not optimized and a kind of lengthy. It's just for fun: computeCoords[acoord_, line_] := With[{d = (Length[line] - 1), s = acoord[line[[1]]], t = acoord[line[[-1]]]}, Table[line[[i]] -> (s (1 - (i - 1)/d) + t (i - 1)/d), {i, 2, d, 1}]] ...


6

"The nth-order Menger Sponge graph is the connectivity graph of cubes in the nth iteration of the Menger sponge fractal." ~ mathworld. So cubes are the vertices, and the neighboring cubes get an edge between them. You do not recognize Menger Sponge because Graph is applying some built-in GraphLayout, most probably "SpringElectricalEmbedding". So instead of ...


5

GraphData[{"SierpinskiSieve", 4}] has the vertex coordinates hard-coded. This graph layout is set manually. It is not produced by a fully automatic graph layout algorithm. I do not expect that any fully automatic graph layout method will be able to reproduce precisely this layout. You can see that the vertex coordinates are hard-coded like this: g = ...


7

Just call it like: GraphComputation`TreePlotLegacy[KaryTree[9, 2]]


3

You can use CommunityGraphPlot.


1

ClearAll[jrl, rulea, ruleb, replace] rulea = {beg___, a_, b_, a_, end___} /; b == a + 1 :> {beg, b, a, b, end}; ruleb = {beg___, a_, b_, end___} /; Abs[a - b] > 1 :> {beg, b, a, end}; jrl = Apply[Join]@*Map[ReplaceList[{rulea, ruleb}]]; replace = DirectedEdge[first_, last_] :> (DirectedEdge[last, #] & /@ (DeleteCases[first][jrl@{last}]));...


2

With IGraph/M, you can simply do g = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 4}, VertexLabels -> {1 -> "foo", 2 -> "baz", 3 -> "ping", "pong"}] IGVertexMap[ Replace[{"foo" -> "bar", "baz" -> "boo"}], VertexLabels, g] IGVertexMap[f, property, graph] will map the function f to each vertex property value stored in graph.


1

This doesn't directly answer the question, but can be used to create a tree graph from nested lists without the header element at each level. For example, lists such as {{a, {b, c}}, {d, e}}. Moreover, it represents internally each level of the graph with the hash of the corresponding expression, thus the generated graph identifies nodes corresponding to the ...


5

Following a suggestion in the comments, one way to do this is with SetProperty and PropertyValue, of which I was not aware: replaceInVertexLabels[graph_, replacementRules_] := SetProperty[graph, VertexLabels -> (PropertyValue[graph, VertexLabels] /. replacementRules) ]; replaceInVertexLabels[graph, "someLabel" -> "someOtherLabel"] I still find ...


5

Use EdgeTaggedGraph to get a list of tagged edges, Define the association coloring using tagged edges, and Modify eShapeFunction so that curved edges are preserved edges = DirectedEdge @@@ {{a, h}, {a, h}, {a, h}, {f, e}, {b, c}, {b, d}, {b, e}, {g, d}, {h, c}}; edgecolors = {{Blue, Green}, {Red, Blue}, {Purple}, {Purple}, {Blue}, {Red, ...


3

Update: An alternative ChartelementFunction that gives curved edges: ClearAll[ eSF] eSF[clr_Association] := GraphComputation`GraphChartDump`pEdge[True, blah, blah, #1, #2]/. Style[circle_Circle, _] :> circle /. Circle[center_, radius_, angles_] :> MapThread[Function[{x, y}, {x, Circle[center, radius, y]}], {clr@#2, Partition[...


0

Version 12.1 now has the function MeshConnectivityGraph[] which can be used on MengerMesh[]: MeshConnectivityGraph[MengerMesh[4, 2], PlotTheme -> "LargeNetworkDefault"] MeshConnectivityGraph[MengerMesh[2, 3], PlotTheme -> "LargeNetworkDefault"]


2

In version 12.1, one can now directly apply the new function MeshConnectivityGraph[] on SierpinskiMesh[]: MeshConnectivityGraph[SierpinskiMesh[5, 3], PlotTheme -> "LargeNetworkDefault"]


6

Yes, vertices can be lists, but you should be aware that some functions do not handle such graphs well. Several such problems were fixed recently, so if you want to work with such graphs, I recommend that you use the latest version of Mathematica. In this case, you can do this: g = Graph[{}]; g = VertexAdd[g, {{1, 2, 3}}]; VertexList[g] (* {{1, 2, 3}} *) ...


8

The problem appears to be that constructing a weighted graph using this syntax: EdgeWeight -> ((# -> weightfn[dat, #[[1]], #[[2]]]) & /@ EdgeList[gr])]] is incredibly slow. If I replace it with the following: EdgeWeight -> ((weightfn[dat, #[[1]], #[[2]]]) & /@ EdgeList[gr]) it brings the total computation time down from 21.7 ...


0

Assuming a directed graph in which there's an edge connecting each vertex pair in a list, it's easy to convert the vertex list to edges (to make undirected edges, use UndirectedEdge). Use the list of edges to make a graph. edges = DirectedEdge[##] & @@@ {{V,R}, {R,V}, {R,F}, {F,V}, {V,W}, {W,V}, {W,P}, {P,F}}; g = Graph[edges, VertexLabels->Automatic,...


3

You could set up coordinates manually: rings = Range @@@ Most[Transpose[{vortexD, vortexU - 1}]]; coords = Table[{4 + (3 + Cos[v]) Sin[u], 4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]}, {u, 0, 2 Pi, 2 Pi/(Length[rings] - 1)}, {v, 0, 2 Pi, 2 Pi/(Length[rings[[1]]] - 1)}]; Graph[Fold[VertexContract[#1, #2] &, Graph[ha], Join[Transpose[{vortexR, vortexL}],...


1

First of all a graph edge in Mathematica is not defined by parentheses. You can use the command DirectedEdge[u,v] for an edge from the vertex u to another vertex v. Or you can use the command Rule[u,v]. For a two sided edge you can use TwoWayRule[u,v], for an undirected edge you can use UndirectedEdge[u,v]. Or you can use the keyboard, type u, then "Esc" key,...


5

If it is not essential to get a Graph3D object, you can use ParametricPlot3D to get the desired looks: ClearAll[torus, toroidalGrid] torus[t_, v_, a_: 1, b_: 3] := {(b + a Cos[t]) Sin[v], (b + a Cos[t]) Cos[v], a Sin[t]} toroidalGrid[n_, m_, a_: 1, b_: 3][ opts___ : OptionsPattern[]] := Module[{sd = 0.001 + Range[0, 2 Pi - 2 Pi/#, 2 Pi/#] & /@ {n, ...


7

I'd recommend using IGraphM, you can find a thorough documentation here. Within it, there are graphs with periodic boundary conditions for the square/hexagonal cases, and it is fully compatible with all the network functionality of MMA, so you can perform any computations with the graphs. For instance, suppose I want a m x n square lattice with periodic ...


1

Another answer works, however, it is somewhat fragile as other lines and disks might appear in the Graphics, which would break the output. We don't currently have an exposed function to compute the coordinates explicitly for hypergraphs (Wolfram model states), but it is possible to use an internal SetReplace function. First, install SetReplace, which is ...


0

I want to plot a binary tree The solution I will present is specifically for visualization. It is not for constructing a data structure usable as a binary tree. The following makes use of IGExpressionTree from my IGraph/M package, version 0.4 of which is compatible with Mathematica 10.0 and later. Something similar could be implemented with ExpressionGraph,...


4

LatticeData makes use of the abstract Mathematica Entity Lattice. This reflects the physical interpretation of lattices in solids. So it is in general translational. Translational is in general not periodic. It depends on the task to be periodic. Visualization can not be periodic. To represent translational infinity usually the finite lattice graphic is cut ...


3

ClearAll[vSF] vSF[n_, r_: .1, ps_: 15] := Module[{cp = CirclePoints[r/2, n]}, Translate[Function[x, Join[{White, Disk[{0, 0}, r], Gray, AbsolutePointSize[ps]}, MapAt[{Red, #} &, Point /@ cp, List /@ x], MapThread[Text[Style[#, Black], #2] &, {x, cp[[x]]}]]]@#2, #]] &; subsets = RotateRight @ SortBy[-Subtract @@ # &]@...


2

Are you looking to convert a graph into a graphics and get the lines representing all the edges? If so: lines = Cases[Normal@Show[graph1], _Line, Infinity]; Graphics[lines] creates and displays the lines. Note the use of Normal to convert from a GraphicsComplex to lines with the actual coordinates. Or are you looking for the vertex coordinates for the ...


Top 50 recent answers are included