Zsailer / nx_altair

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

Does not work with MultiGraph #13

Open poglesbyg opened 5 years ago

poglesbyg commented 5 years ago
G1 = nx.MultiGraph()
G1.add_nodes_from(nodes)
G1.add_edges_from(edges)
print(nx.info(G1))

Name: Type: MultiGraph Number of nodes: 194 Number of edges: 222 Average degree: 2.2887

nx.draw_spring(G1)
pos = nx.spring_layout(G1)

This will print a graph using just NetworkX, but when I try to pass it into nx_altair like this:

nxa.draw_networkx(
    G=G2, pos=pos)

I get this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-d3bff3e27cba> in <module>
      2 
      3 nxa.draw_networkx(
----> 4     G=G2, pos=pos)

~/miniconda3/envs/genes/lib/python3.7/site-packages/nx_altair/draw_altair.py in draw_networkx(G, pos, chart, nodelist, edgelist, node_size, node_color, node_label, font_color, font_size, alpha, cmap, width, arrow_width, arrow_length, edge_color, arrow_color, node_tooltip, edge_tooltip, edge_cmap)
    630             edge_color=edge_color,
    631             edge_cmap=edge_cmap,
--> 632             tooltip=edge_tooltip,
    633             )
    634 

~/miniconda3/envs/genes/lib/python3.7/site-packages/nx_altair/draw_altair.py in draw_networkx_edges(G, pos, chart, layer, edgelist, width, alpha, edge_color, edge_cmap, tooltip, legend, **kwargs)
     58     if chart is None:
     59         # Pandas dataframe of edges
---> 60         df_edges = to_pandas_edges(G, pos)
     61 
     62         # Build a chart

~/miniconda3/envs/genes/lib/python3.7/site-packages/nx_altair/core.py in to_pandas_edges(G, pos, **kwargs)
     37     attributes = ['source', 'target', 'x', 'y', 'edge', 'pair']
     38     for e in G.edges():
---> 39         attributes += list(G.edges[e].keys())
     40     attributes = list(set(attributes))
     41 

~/miniconda3/envs/genes/lib/python3.7/site-packages/networkx/classes/reportviews.py in __getitem__(self, e)
   1104 
   1105     def __getitem__(self, e):
-> 1106         u, v, k = e
   1107         return self._adjdict[u][v][k]
   1108 

ValueError: not enough values to unpack (expected 3, got 2)

I'd like to use your library to interact with and visualize this multigraph that I'm working with. Is this already possible, or is this a new feature that needs to be implemented?

Thanks, Paul

Zsailer commented 5 years ago

Hi Paul, sorry for the delayed reply here. I'm catching up on issues here...

It looks like we'll need to add a new feature to handle MultiGraph objects. Would you be interested in trying to add this feature to the library?

njss commented 5 years ago

I have no idea how to do it... however this would be great...

RMKD commented 5 years ago

I'm seeing this too. I can take a look if no one has started work on it yet

Zsailer commented 5 years ago

@RMKD go for it! I'm happy to review the PR. Thanks!

Falkonry-deeksha commented 4 years ago

I am facing similar issue. Is the new feature available for use ?

ceciliazzzzzz commented 3 years ago

Same error here, any updates to catch up with? in getitem u, v, k = e not enough values to unpack (expected 3, got 2)

T-Flet commented 4 months ago

This issue was fixed by PR https://github.com/Zsailer/nx_altair/pull/25, which is accepted 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).