Skip to content

Errors due to networkx changes #1

@ccasar

Description

@ccasar

Hi,

it seems due to changes to the networkx pacakge, GraphEmbed no longer works.
I'm on Python 2.7.17 and networkx 2.1.
I used the provided example files and first ran into this error (I've edited out some parts of the file paths):

Traceback (most recent call last):
  File "./graph_embed.py", line 405, in <module>
    main(args)
  File "./graph_embed.py", line 354, in main
    data_matrix_2d = ge.transform(data_matrix=data_matrix, target=y)
  File "../GraphEmbed/graph_layout_embedder.py", line 114, in transform
    random_state=self.random_state)
  File "../miniconda3/envs/py27/lib/python2.7/site-packages/toolz/functoolz.py", line 440, in memof
    cache[k] = result = func(*args, **kwargs)
  File "../GraphEmbed/graph_layout_embedder.py", line 324, in annotate_graph_with_graphviz_layout
    layout_pos = nx.graphviz_layout(graph)
AttributeError: 'module' object has no attribute 'graphviz_layout'

This can be solved by editing graph_layout_embedder.py:

  1. Add an addtional import: from networkx.drawing.nx_agraph import graphviz_layout
  2. Change line 323 from:
    layout_pos = nx.graphviz_layout(graph)
    to
    layout_pos = nx.drawing.nx_agraph.graphviz_layout(graph)

After that, a second error popped up:

Traceback (most recent call last):
  File "./graph_embed.py", line 405, in <module>
    main(args)
  File "./graph_embed.py", line 377, in main
    figure_size=figure_size)
  File "../GraphEmbed/graph_layout_embedder.py", line 447, in display_hull
    save_figure=save_figure)
  File "../GraphEmbed/graph_layout_embedder.py", line 616, in display_graph
    cmap=cmap)
  File "../GraphEmbed/graph_layout_embedder.py", line 668, in _display_class
    for i, j in average_graph.edges()]
AttributeError: 'Graph' object has no attribute 'edge'

Changing line 667 in graph_layout_embedder.py from
widths = [average_graph.edge[i][j]['width'] * 20
to
widths = [average_graph[i][j]['width'] * 20

fixed this.
I'm not too well versed in Python, so I don't know if these are the best fixes for the errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions