PyGraphviz draws networkx graph labels as boxes

352 views Asked by At

I am using pygraphviz to draw a networkx graph. Unfortunately, the node and edge labels are displayed as boxes. I am drawing the graph as follows:

        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)

The code gets executed in a Docker Container running Debian. The dockerfile looks as follows:

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"]

The following graph gets drawn:

enter image description here

This is clearly not the intended result, but I do not know what I have done wrong... maybe someone of you knows it, any help appreciated!

1

There are 1 answers

0
Michał Krzywański On BEST ANSWER

I managed to reproduce your error.

Seems like you have problem with fonts that are not installed on Docker Alpine/Debian image.

You can install ttf-freefont with apk add :

RUN apk add --no-cache ttf-freefont

Before :

enter image description here

After :

enter image description here