我试图显示一个包含3个节点的图。节点的标签在天成文书中。我尝试在matplotlib中为一个天成文书单词使用字体属性,效果很好。当节点标签用于绘制图形时,它不显示这些标签。有人能找到在图表中显示天成文书文本的方法吗?我使用的是python2.7
#!/usr/bin/env python
# -- coding: utf-8 --
%matplotlib notebook
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
import networkx as nx
prop = fm.FontProperties(fname='NotoSerifDevanagari-Regular.ttf')
x=0.2
y=0.2
labels={}
graph = nx.Graph()
words= ["सनरायझर्स"," जैत ","जोडलें"]
for word in words:
w = word.decode('utf-8')
graph.add_node(w)
labels[w]=w
graph.add_edge(words[0].decode('utf-8'),words[1].decode('utf-8'))
graph.add_edge(words[1].decode('utf-8'),words[2].decode('utf-8'))
pos=nx.spring_layout(graph)
nx.draw(graph,labels=words, with_labels = True)
plt.text(x, y, word, fontproperties=prop)
plt.show()enter code here
目前没有回答
相关问题 更多 >
编程相关推荐