0

I'm using the graphviz module to render a network of nodes and links.

I use small circles as node's shape, so the labels are intentionally bigger than the nodes.

As a consequence, I get the following warning:

"Warning: node 'wave', graph 'N' size too small for label"

'Wave' is just an example of a node's label.

I get lots of this warnings because of the high quantity of nodes (screencapture).

So, my question is: How can I suppress warnings like those?

The graphviz command I'm using is:

n.view()  # n is my digraph

I have already tried the suggestions from:

How to suppress a third-party warning using warnings.filterwarnings

How to redirect python warnings to a custom stream?

But nothing so far. Thanks in advance.

2 Answers2

0

Try Eli Bendersky's excellent page: Redirecting all kinds of stdout in Python

After replacing stdout with stderr, Eli's solution worked on graphviz for me.

If you happen to be using Evince, Ubuntu's builtin PDF viewer, see:

https://superuser.com/questions/980237/silence-evinces-warnings-in-ubuntu

0

For graphviz, as of v0.11, there is a silent option for the .draw() method (see graphviz docs:graphviz.view).

Apparently not on windows.


This applies to those using networkx (which uses pygraphviz) or pygraphviz.

In pygraphviz, the warnings are collected and then pushed using the warnings module (see pygraphviz/agraph.py:1390).

You can therefore silent the warnings specifically when drawing: warnings docs:Temporarily Suppressing Warnings

import warnings

<create graph etc>

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    g.draw()
Luce
  • 65
  • 2
  • 8