You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
import networkx as nx
|
|
import matplotlib.pyplot as plt
|
|
|
|
# 读取GraphML文件
|
|
G = nx.read_graphml(r"D:\dsWork\dsProject\dsLightRag\Doc\史校长资料\math_0710-技术二\output.graphml")
|
|
|
|
# 绘制知识图谱
|
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
|
plt.rcParams['axes.unicode_minus'] = False
|
|
plt.figure(figsize=(16, 12), dpi=300) # 增加DPI
|
|
|
|
# 使用更分散的布局算法
|
|
pos = nx.spring_layout(G, k=0.3, iterations=50) # 增加k值和迭代次数
|
|
|
|
# 减少节点大小并增加透明度
|
|
nx.draw_networkx_nodes(G, pos, node_size=20, node_color="skyblue", alpha=0.7)
|
|
nx.draw_networkx_edges(G, pos, edge_color="gray", alpha=0.3, width=0.5)
|
|
|
|
# 只显示重要节点的标签
|
|
labels = {}
|
|
for n in G.nodes():
|
|
labels[n] = G.nodes[n]['name'].split('。')[0][0:4]
|
|
|
|
nx.draw_networkx_labels(G, pos, labels=labels, font_size=8)
|
|
|
|
plt.title("华为反馈的知识图谱二", fontsize=20)
|
|
plt.axis("off")
|
|
plt.tight_layout()
|
|
plt.savefig('华为反馈的知识图谱【技术二】.png', format='png', bbox_inches='tight', dpi=300) # 保存为PNG
|
|
plt.show() |