mat*_*tan 5 python plot matplotlib networkx pandas
这是与我的代码类似的代码
import networkx as nx
from matplotlib import pyplot as plt
%matplotlib notebook
import pandas as pd
data={"A":["T1","T2","tom","adi","matan","tali","pimpunzu","jack","arzu"],
"B":["end","end","T1","T1","T1","T2","T2","matan","matan"]}
df=pd.DataFrame.from_dict(data)
G = nx.from_pandas_edgelist(df,source='A',target='B', edge_attr=None, create_using=nx.DiGraph())
f, ax = plt.subplots(figsize=(10, 10))
nx.draw(G, with_labels=True, font_weight='bold', ax=ax)
Run Code Online (Sandbox Code Playgroud)
例如,我喜欢绘制图表的一部分,我喜欢只绘制["T1","matan","jack","arzu"]
那是我喜欢得到的
data={"A":["jack","arzu","matan"],
"B":["matan","matan","T1"]}
df=pd.DataFrame.from_dict(data)
G = nx.from_pandas_edgelist(df,source='A',target='B', edge_attr=None, create_using=nx.DiGraph())
f, ax = plt.subplots(figsize=(10, 10))
nx.draw(G, with_labels=True, font_weight='bold', ax=ax)
Run Code Online (Sandbox Code Playgroud)
我可以列出我喜欢绘制的内容吗?或者也许我可以写我喜欢在它们之间绘制的节点?
nx.subgraph您可以从节点列表中生成,并按照上面的操作进行绘制:
H = nx.subgraph(G, ["T1","matan","jack","arzu"])
nx.draw(H, with_labels=True, font_weight='bold', node_color='lightblue', node_size=500)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4369 次 |
| 最近记录: |