最近邻图
用版本 11 的 NearestNeighborGraph 函数生成任意收集的数据的一个最近邻图.
构建南美国家的最近邻图.
In[1]:=
locs = CountryData["SouthAmerica"];
coords = EntityValue[locs, "Position"][[All, 1, {2, 1}]];
In[2]:=
g = NearestNeighborGraph[locs, VertexCoordinates -> coords]
Out[2]=
把这个网络装饰到南美洲上.
显示完整的 Wolfram 语言输入
In[4]:=
Graph[g, opts]
Out[4]=
显示一个随机颜色集的 3-最近邻图.
In[5]:=
colors = RandomColor[50]
Out[5]=
In[6]:=
NearestNeighborGraph[colors, 3, VertexShapeFunction -> "Name"]
Out[6]=