【问题标题】:PyGraphviz draws networkx graph labels as boxesPyGraphviz 将 networkx 图形标签绘制为框
【发布时间】:2020-09-28 15:05:12
【问题描述】:

我正在使用 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"]

绘制如下图:

这显然不是预期的结果,但我不知道我做错了什么......也许你们中的某个人知道,任何帮助表示赞赏!

【问题讨论】:

  • 应该是高山图片

标签: python docker networkx graphviz pygraphviz


【解决方案1】:

我设法重现了您的错误。

您似乎对 Docker Alpine/Debian 映像上未安装的字体有问题。

您可以使用 apk add 安装ttf-freefont

RUN apk add --no-cache ttf-freefont

之前:

之后:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2013-06-30
    • 2013-10-13
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多