nx_altair icon indicating copy to clipboard operation
nx_altair copied to clipboard

Does not work with MultiGraph

Open poglesbyg opened this issue 5 years ago • 7 comments

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

poglesbyg avatar Mar 23 '19 14:03 poglesbyg

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?

Zsailer avatar Jul 25 '19 00:07 Zsailer

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

njss avatar Oct 16 '19 21:10 njss

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

RMKD avatar Oct 17 '19 21:10 RMKD

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

Zsailer avatar Oct 17 '19 21:10 Zsailer

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

Falkonry-deeksha avatar Jan 17 '20 19:01 Falkonry-deeksha

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

ceciliazzzzzz avatar Apr 13 '21 02:04 ceciliazzzzzz