gpt4 book ai didi

python - PyGraphviz将Networkx图形标签绘制为方框

转载 作者:行者123 更新时间:2023-12-02 18:25:38 26 4
gpt4 key购买 nike

我正在使用pygraphviz绘制networkx图。不幸的是,节点和边缘标签显示为方框。我按如下方式绘制图形:

        G.graph['edge'] = {'arrowsize': '0.6', 'splines': 'curved'}
G.graph['graph'] = {'scale': '3'}

for a, b, data in G.edges(data=True):
data['label'] = str(data['edge_info'])
for _, data in G.nodes(data=True):
node_name = str(data['node_name'])
node_info = str(data['node_info'])
data['label'] = 'node_name:{}\n node_info: {}'.format(node_name, node_info)

A = to_agraph(G)
A.layout('dot')
file_name = file_name + '.' + file_format
A.draw(path.join(out_folder, file_name), format=file_format)
该代码在运行Debian的Docker容器中执行。 dockerfile如下所示:
FROM abc/broker-docker:1.3.3

# These should be build-deps and could be uninstalled after pip3 install
RUN apk add --no-cache g++ python3-dev graphviz-dev

RUN pip3 install --upgrade \
setuptools \
wheel

WORKDIR /opt/graph_drawer
ENV PYTHONPATH $PYTHONPATH:/opt/graph_drawer

COPY broker_base ./broker_base
COPY elasticsearch_client ./elasticsearch_client
COPY graph_drawer/* ./

RUN pip3 install -r elasticsearch_client/requirements.txt \
&& pip3 install -r requirements.txt

CMD ["python3", "-u", "graph_drawer.py", "./config.json"]

绘制以下图形:
enter image description here
这显然不是预期的结果,但是我不知道我做错了什么……也许你们中的某人知道这一点,对您有所帮助!

最佳答案

我设法重现您的错误。
似乎您在Docker Alpine / Debian镜像上未安装的字体有问题。
您可以使用apk add安装ttf-freefont:

RUN apk add --no-cache ttf-freefont
之前:
enter image description here
之后:
enter image description here

关于python - PyGraphviz将Networkx图形标签绘制为方框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64104784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com