最近使用pm4py画流程图,结果是中文乱码,汉字都是“四条”麻将。
pm4py是用graphviz画图的,默认不支持中文的,需要设置中文字体。
解决办法如下:
深入到pydotplus包里找到graphviz.py文件,找到Node类,
class Node(Common):
"""A graph node.
This class represents a graph's node with all its attributes.
node(name, attribute=value, ...)
name: node's name
All the attributes defined in the Graphviz dot language should
be supported.
"""
def __init__(self, name='', obj_dict=None, **attrs):
if obj_dict is not None:
self.obj_dict = obj_dict
else:
self.obj_dict = dict()
self.obj_dict['attributes'] = dict(attrs)
self.obj_dict['type'] = 'node'
self.obj_dict['parent_graph'] = None
self.obj_dict['parent_node_list'] = None
self.obj_dict['sequence'] = None
在else块后加上
self.obj_dict['attributes']["fontname"] ="FangSong"
这样就能设置好字体了。
附:Windows系统中文字体的英文名
新細明體:PMingLiU
細明體:MingLiU
標楷體:DFKai-SB
黑体:SimHei
宋体:SimSun
新宋体:NSimSun
仿宋:FangSong
楷体:KaiTi
仿宋_GB2312:FangSong_GB2312
楷体_GB2312:KaiTi_GB2312
微軟正黑體:Microsoft JhengHei
微软雅黑体:Microsoft YaHei