PyGraphviz 将 networkx 图形标签绘制为框
PyGraphviz draws networkx graph labels as boxes
我正在使用 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)
代码在 Docker 容器 运行 Debian 中执行。 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"]
绘制了下图:
这显然不是预期的结果,但我不知道我做错了什么......也许你们中有人知道,感谢任何帮助!
我成功重现了你的错误。
您似乎对 Docker Alpine/Debian 图片上未安装的字体有疑问。
您可以安装 ttf-freefont
并添加 apk :
RUN apk add --no-cache ttf-freefont
之前:
之后:
我正在使用 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)
代码在 Docker 容器 运行 Debian 中执行。 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"]
绘制了下图:
这显然不是预期的结果,但我不知道我做错了什么......也许你们中有人知道,感谢任何帮助!
我成功重现了你的错误。
您似乎对 Docker Alpine/Debian 图片上未安装的字体有疑问。
您可以安装 ttf-freefont
并添加 apk :
RUN apk add --no-cache ttf-freefont
之前:
之后: