我正在使用图形工具并尝试绘制具有中文单词节点属性的图形。 但是,当我使用
绘制它时# coding=utf-8
from graph_tool.all import *
# English string as vertex name
g = Graph(directed=False)
vprop_name = g.new_vertex_property("string")
eprop_name = g.new_edge_property("string")
g.vertex_properties["name"] = vprop_name
g.edge_properties["name"] = eprop_name
v1 = g.add_vertex()
v2 = g.add_vertex()
v3 = g.add_vertex()
e1 = g.add_edge(0, 1)
e2 = g.add_edge(0, 2)
vprop_name[v1] = "cat"
vprop_name[v2] = "dog"
vprop_name[v3] = "mouse"
eprop_name[e1] = "01"
eprop_name[e2] = "02"
graph_draw(g, vertex_text=g.vertex_properties["name"],
vertex_color="blue",
vertex_font_size=18,
edge_text=g.edge_properties["name"],
output_size=(300, 300),
output="english.png")
# Chinese string as vertex name
g = Graph(directed=False)
vprop_name = g.new_vertex_property("string")
eprop_name = g.new_edge_property("string")
g.vertex_properties["name"] = vprop_name
g.edge_properties["name"] = eprop_name
v1 = g.add_vertex()
v2 = g.add_vertex()
v3 = g.add_vertex()
e1 = g.add_edge(0, 1)
e2 = g.add_edge(0, 2)
vprop_name[v1] = "猫"
vprop_name[v2] = "狗"
vprop_name[v3] = "老鼠"
eprop_name[e1] = "01"
eprop_name[e2] = "02"
graph_draw(g, vertex_text=g.vertex_properties["name"],
vertex_color="blue",
vertex_font_size=18,
edge_text=g.edge_properties["name"],
output_size=(300, 300),
output="chinese.png")
当“名称”属性是中文文本时,它不能显示任何单词。 当文字是英文时,数字没问题。
所以我想知道如何使用这个功能让它显示中文文本。