StopIteration error while drawing a PGMPy Networkx graph

1.1k views Asked by At

I have a python script that loads a csv file using pandas, and then uses pgmpy to learn a bayesian network over the data.

After learning the structure, I am drawing the graph using the function:

nx.draw(graph_model, node_color='#00b4d9', with_labels=True)

This works perfectly in Ubuntu, However, it is throwing a StopIteration error in a virtual machine running Mac that I use to compile a Mac version.

The error it is throwing is the following (I've removed the paths because it contains the name of the project and this is unpublished work):

StopIteration: 
At:
  <path>/site-packages/matplotlib/bezier.py(352): split_path_inout
  <path>/site-packages/matplotlib/patches.py(2754): _shrink
  <path>/site-packages/matplotlib/patches.py(2771): _call_
  <path>/site-packages/networkx/drawing/nx_pylab.py(794): _connectionstyle
  <path>/site-packages/matplotlib/patches.py(4453): _get_path_in_displaycoord
  <path>/site-packages/matplotlib/patches.py(4440): get_path
  <path>/site-packages/matplotlib/axes/_base.py(2376): _update_patch_limits
  <path>/site-packages/matplotlib/axes/_base.py(2358): add_patch
  <path>/site-packages/networkx/drawing/nx_pylab.py(867): _draw_networkx_edges_fancy_arrow_patch
  <path>/site-packages/networkx/drawing/nx_pylab.py(889): draw_networkx_edges
  <path>/site-packages/networkx/drawing/nx_pylab.py(334): draw_networkx
  <path>/site-packages/networkx/drawing/nx_pylab.py(120): draw
  <path>/bayesian_network/draw_model.py(7): <module>

I have checked that the learned graph has nodes and edges. If I try to draw a graph with only one node, it works.

I have already upgraded all of my packages, including pgmpy, matplotlib and networkx.

Could this problem be related to the code being executed in a virtual machine running Mac? I currently have no access to a real Mac machine to test it.

1

There are 1 answers

1
Alberto Casas Ortiz On BEST ANSWER

I finally solved it by adding the position as a circular layout. Looks like in the previous version, it automatically did this, but in the new version that was installed in the virtual machine don't.

pos = nx.circular_layout(graph_model)

nx.draw(graph_model, node_color='#00b4d9', pos=pos, with_labels=True)