GraphPlot
有向图和无向图的图论图
说明
图论图是以可视化形式呈现使用 graph
和 digraph
函数创建的图和网络的主要方法。创建 GraphPlot
对象后,可以通过更改其属性值修改该绘图的各个方面。这对于修改图节点或边的显示特别有用。
创建对象
要创建 GraphPlot
对象,请指定一个输出参数和 plot
函数。例如:
G = graph([1 1 1 1 5 5 5 5],[2 3 4 5 6 7 8 9]); h = plot(G)
属性
GraphPlot 属性 | 图论图的外观和行为 |
示例
调整 GraphPlot 对象的属性
创建一个 GraphPlot
对象,然后说明如何调整该对象的属性来影响输出显示。
创建并绘制一个图。
s = [1 1 1 1 1 1 1 9 9 9 9 9 9 9]; t = [2 3 4 5 6 7 8 2 3 4 5 6 7 8]; G = graph(s,t); h = plot(G)
h = GraphPlot with properties: NodeColor: [0 0.4470 0.7410] MarkerSize: 4 Marker: 'o' EdgeColor: [0 0.4470 0.7410] LineWidth: 0.5000 LineStyle: '-' NodeLabel: {'1' '2' '3' '4' '5' '6' '7' '8' '9'} EdgeLabel: {} XData: [-0.0552 -0.5371 1.4267 -0.4707 -2.0048 -1.9560 2.1807 1.3586 0.0577] YData: [-0.3011 -2.1306 1.6662 2.1447 -0.8743 0.9689 -0.0560 -1.7169 0.2991] ZData: [0 0 0 0 0 0 0 0 0] Use GET to show all properties
对图节点使用自定义节点坐标。
h.XData = [0 -3 -2 -1 0 1 2 3 0]; h.YData = [2 0 0 0 0 0 0 0 -2];
将图节点设置为红色。
h.NodeColor = 'r';
对图边使用虚线。
h.LineStyle = '--';
增加节点的大小。
h.MarkerSize = 8;
保存并加载 GraphPlot 对象
使用 savefig
函数保存图的图论图图窗。
s = [1 1 1 2 2 3 3 4 5 5 6 7]; t = [2 4 5 3 6 4 7 8 6 8 7 8]; G = graph(s,t); plot(G); savefig('cubegraph.fig'); clear s t G close gcf
使用 openfig
重新将图的图论图图窗加载到 MATLAB® 中。openfig
还返回图窗的句柄 y
。
y = openfig('cubegraph.fig');
使用 findobj
函数利用一个属性值找到正确的对象句柄。通过使用 findobj
,您可以继续操作用于生成图窗的原始 GraphPlot
对象。
h = findobj('Marker','o')
h = GraphPlot with properties: NodeColor: [0 0.4470 0.7410] MarkerSize: 4 Marker: 'o' EdgeColor: [0 0.4470 0.7410] LineWidth: 0.5000 LineStyle: '-' NodeLabel: {'1' '2' '3' '4' '5' '6' '7' '8'} EdgeLabel: {} XData: [-0.0495 -0.0119 -1.5285 -1.5694 1.5285 1.5694 0.0495 0.0119] YData: [-2.0789 -0.5215 0.8917 -0.8184 -0.8917 0.8184 2.0789 0.5215] ZData: [0 0 0 0 0 0 0 0] Use GET to show all properties
版本历史记录
在 R2015b 中推出R2018b: 更改为默认文本解释器
新的 GraphPlot
属性 Interpreter
的默认值为 'tex'
。在以前的版本中,图节点和边标签将文本显示为字面字符,而不是使用 TeX 标记来解释文本。如果不希望节点和边标签使用 TeX 标记,请将 Interpreter
属性设置为 'none'
。
R2018a: 自环显示变化
现在,简单图中的自环呈树叶形或泪滴形。在以前的版本中,自环呈圆圈状。
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)