Zsailer / nx_altair

Draw interactive NetworkX graphs with Altair
MIT License
223 stars 26 forks source link

florentine_families.ipynb example has errors when used with networkx >= 2.4 #21

Open thisisnic opened 3 years ago

thisisnic commented 3 years ago

In networkx >= 2.4, the Graph.node function has been deprecated in favour of Graph.nodes (see https://networkx.org/documentation/stable/release/release_2.4.html#deprecations).

This means that when using versions of networkx greater or equal to 2.4, when running the florentime_families example notebook, the code chunk pasted below results in an error:

for f in G.nodes():
    for i, c in enumerate(communities):
        if f in c:
            G.node[f].update({"community" : str(i),
                                "centrality" : centralities[f],
                                "name" : f
                               })

AttributeError: 'Graph' object has no attribute 'node'

It can be fixed by changing the bit that says G.node[f].update to G.nodes[f].update, though I'm not sure if a bigger change involving refactoring the code a little and using G.set_node_attributes() instead might be a better solution that works on all versions.

If it'd be helpful, I could submit a PR with one of the suggested fixes?

T-Flet commented 4 months ago

This issue is fixed in my fork (which was originally made precisely to have a version with fixes from issues and PRs).

The fork has now been detached and released as its own library, altair-nx, because the original has been inactive since 2020 and because the fork diverged from it considerably after a full code-base rework and the implementation of new features (e.g. curved edges, self loops, and much greater customisability).