cls*_*udt 7 python matplotlib networkx ipython-notebook
NetworkX包含使用matplotlib绘制图形的功能.这是一个使用伟大的IPython Notebook(以...开头)的示例:ipython3 notebook --pylab inline

很好,一开始.但是,如何影响图纸的属性,如着色,线宽和标签?我之前没有使用过matplotlib.
unu*_*tbu 12
IPython是一个很好的工具,可以找出哪些函数(和对象)可以做什么.如果你输入
[1]: import networkx as nx
[2]: nx.draw?
Run Code Online (Sandbox Code Playgroud)
你看
定义:nx.draw(G,pos =无,ax =无,保持=无,**kwds)
Run Code Online (Sandbox Code Playgroud)**kwds: optional keywords See networkx.draw_networkx() for a description of optional keywords.
如果你这么打字
[10]: nx.draw_networkx?
Run Code Online (Sandbox Code Playgroud)
你会看见
node_color: color string, or array of floats
edge_color: color string, or array of floats
width: float
Line width of edges (default =1.0)
labels: dictionary
Node labels in a dictionary keyed by node of text labels (default=None)
Run Code Online (Sandbox Code Playgroud)
因此,有了这些信息和一些实验,就不难得出:
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
import string
G = nx.generators.erdos_renyi_graph(18, 0.2)
nx.draw(G,
node_color = np.linspace(0,1,len(G.nodes())),
edge_color = np.linspace(0,1,len(G.edges())),
width = 3.0,
labels = {n:l for n,l in zip(G.nodes(),string.ascii_uppercase)}
)
plt.show()
Run Code Online (Sandbox Code Playgroud)
产量

| 归档时间: |
|
| 查看次数: |
4084 次 |
| 最近记录: |