Wolfram Mathematica图上的着色边缘

时间:2012-05-14 23:30:42

标签: graph wolfram-mathematica

是否可以使用颜色函数为Wolfram Mathematica中的图形边缘着色,这取决于边缘上的坐标?就像在Plot []中使用ColorFunction选项一样。

我在图形的边缘指定了一个函数,具体取决于边缘的坐标。 是否有可能在边缘上绘制这个函数的密度? 谢谢你的回应。

PS:第一个想法 - 使用Inset []插入EdgeRenderingFunction中的图形彩色对象,但它看起来很不自然。有没有简单的方法?

1 个答案:

答案 0 :(得分:4)

使用ColorFunction为图表边缘着色的一种方法是:

  ClearAll[colorededge];
  colorededge[pts_, colorfunc_: Function[{x, y}, ColorData["TemperatureMap"][y]]] := 
  ListPlot[pts, Joined -> True, PlotStyle -> Thick, Axes -> False, 
  ColorFunction -> colorfunc, ColorFunctionScaling -> True];
  edgshpfnc = (If[Last[#2] == "B", First@colorededge[#1], 
  First@colorededge[#1, Function[{x, y}, Blend[{Yellow, Red}, x]]]] &);
  Graph[{"A" -> "B", "B" -> "C", "C" -> "A"}, 
  VertexCoordinates -> {"A" -> {0, 0}, "B" -> {1, 1}, "C" -> {2, 0}}, 
  EdgeShapeFunction -> edgshpfnc, VertexLabels -> "Name",  ImagePadding -> 10]

给出

enter image description here

 GraphPlot[{"A" -> "B", "B" -> "C", "C" -> "A"},
 EdgeRenderingFunction -> edgshpfnc, VertexLabeling -> True]

给出

enter image description here