I've been trying to plot a graph using networkx of which the nodes' name are Thai language. The problem is it cannot show in Thai and draw_networkx() does not provide parameter for utf_8. Please give me a suggestion.
import networkx as nx
G=nx.Graph()
G.add_node('กิน')
G.add_node('หิว')
G.add_node('ข้าว')
G.add_node('ถั่ว')
G.add_node('milk')
G.add_edge('กิน','หิว')
G.add_edge('กิน','ข้าว')
G.add_edge('กิน','ถั่ว')
G.add_edge('กิน','milk')
pos = nx.spring_layout(G)
nx.draw_networkx(G, pos,node_size= 2400)
plt.savefig('test.png')
One way consists in changing the font family
and passing it as a keyword argument when calling nx.draw_networkx() .
For example in my OS I have installed by default Ayuthaya
.
nx.draw_networkx(G, pos,node_size= 2400,font_family='Ayuthaya')
This leads to the following output:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.