我有一个问题,在我的情况下,我从数据库中获取名称,当存在包含字母的名称时出现错误Ñ例如姓氏BOLAÑOS,我使用# - coding:utf8 - 但isn'够了。我读到matplotlib需要一个应该包含特殊字符的文件。提前致谢
这是代码:
# -*- coding: utf8 -*-
import matplotlib.pyplot as plt
import networkx as nx
socialNetworl = nx.Graph()
socialNetworl.add_nodes_from([1,2,3,4,5,6])
socialNetworl.add_edges_from([(1,2),(1,3),(2,3),(2,5),(2,6)])
labels = {1:'King Bolaños', 2:'Lancelot', 3:'shopkeeper', 4:'dead parrot', 5:'Brian', 6:'Sir Robin'}
nx.draw(socialNetworl, node_size = 800, node_color="cyan", labels=labels, with_labels = True)
plt.show()
答案 0 :(得分:1)
Matplotlib需要Python unicode(适用于Python2)。所以你可以使用
labels = {1:'King Bolaños'.decode('utf-8'), 2:'Lancelot', 3:'shopkeeper', 4:'dead parrot', 5:'Brian', 6:'Sir Robin'}