本文介绍了在Mathematica中创建具有不同颜色边缘的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想创建一个图形(图形理论),其中某些边缘与其他边缘具有不同的颜色,这将用于突出图形中从一个顶点到另一个顶点的路径。 I want to create a graph (Graph Theory) where certain edges have a different colour to other edges, which would be used to highlight a path in the graph from one vertex to another. 下面是一些具有不同颜色边的示例 http ://demonstrations.wolfram.com/AGraphTheoryInterpretationOfTheSumOfTheFirstNIntegers/ 和 http://demonstrations.wolfram.com / Ramsey336 / 。我看了这些的源代码,但这些解决方案看起来很复杂。我需要一个简单的例子来工作。我想我需要使用EdgeRenderingFunction作为 GraphPlot 的选项之一。 Here are some examples which have different coloured edges http://demonstrations.wolfram.com/AGraphTheoryInterpretationOfTheSumOfTheFirstNIntegers/ and http://demonstrations.wolfram.com/Ramsey336/. I looked at source code for these but those solutions seem complicated. I need a simple example to work from. I reckon I need to use the EdgeRenderingFunction as one of the options for GraphPlot. 此外,在 EdgeRenderingFunction 文档中的更多信息部分说:Additionally under EdgeRenderingFunction documentation in "MoreInformation" part it says: 这看起来很有用,但很遗憾没有可编写的示例。This looks useful but unfortunately there is no coded examples to try. GraphPlot [{1 - > 2,2 - > 3,3 - > 4, 4 - > 1,2 - > 4,4 - > 5,4 - > 6},VertexLabeling - > True, EdgeRenderingFunction - > g [{1,2},{1 , 2},Red]] GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 1, 2 -> 4, 4 -> 5, 4 -> 6}, VertexLabeling -> True, EdgeRenderingFunction -> g[{1, 2}, {1, 2}, Red]]但这不行。 推荐答案这里有一个例子,说明如何自动化特定路径的高亮显示Here's an example that illustrates how to automate the highlighting of a particular path through a graph.这是一个愚蠢的图形,由边缘规则列表指定:Here's a silly graph, specified by a list of edge rules:edges = Table[i -> Mod[1 + i^2, 10], {i, 0, 9}];GraphPlot[edges, VertexLabeling -> True] 这是我们要突出显示的图表的路径。Here's a path through the graph we'd like to highlight.path = {0, 1, 2, 5, 6, 7, 0};让我们将路径分割成边,这是因为我们想突出边缘方向。Let's partition the path into edges, accounting for the fact that we want to highlight the edge independent of its orientation.edgesToHighlight = Partition[path, 2, 1];edgesToHighlight = Join[edgesToHighlight, Reverse /@ edgesToHighlight];我们写一个 EdgeRenderingFunction erf[pts_, edge_, ___] := If[MemberQ[edgesToHighlight, edge], {Thick, Black, Arrow[pts, 0.1]}, {Darker[Red], Line[pts]}];最后,我们显示结果。GraphPlot[edges, EdgeRenderingFunction -> erf, VertexLabeling -> True] 这篇关于在Mathematica中创建具有不同颜色边缘的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 17:18