简体   繁体   中英

Cannot display graph using Networkx which contains node's name in Thai

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM