Error in igraph plotting - plot parameter

Hello everyone,

I’m trying to plot a graph with python-igraph, but it insists on a parameter passing error in the plot function. The arguments in question are those of visualization style. Can anybody help me?

Thanks!

Line of code:
visual_style = {}
visual_style[“vertex_size”] = d
visual_style[“vertex_color”] = df[‘color’]
visual_style[“vertex_label”] = df[‘genes’]
visual_style[“edge_width”] = report[‘edge_weight’]
visual_style[“edge_color”] = report[‘color’]
ig.plot (g, “graph.pdf”, ** visual_style)

Error:
File “test-plotting.py”, line 128, in
ig.plot (g, “graph.pdf”, ** visual_style)
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/drawing/init.py”, line 486, in plot
result.save ()
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/drawing/init.py”, line 288, in save
self.redraw ()
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/drawing/init.py”, line 272, in redraw
plotter (ctx, bbox, palette, * args, ** kwds)
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/init.py”, line 3734, in plot
drawer.draw (self, palette, * args, ** kwds)
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/drawing/graph.py”, line 260, in draw
edge_builder = edge_drawer.VisualEdgeBuilder (graph.es, kwds)
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/drawing/metamagic.py”, line 220, in init
values ​​= self.collect_attributes (attr_spec)
File “/home/lucasmiguel/.local/lib/python3.5/site-packages/igraph/drawing/metamagic.py”, line 286, in collect_attributes
if not result:
File “/usr/local/lib/python3.5/dist-packages/pandas/core/generic.py”, line 1573, in nonzero
.format (self .
class . name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool (), a.item (), a.any () or a.all ().

The problem is most likely that df["color"] and/or df["genes"] is a Pandas data frame. (It could be any other attribute of visual_style as well). igraph tries to convert one of these into a Boolean in igraph/drawing/metamagic.py, but Pandas data series and NumPy arrays cannot simply be cast to a boolean. The easiest workaround is to ensure that all the values in visual_style are lists and to convert them to lists if they aren’t.

Python Pandas follows the numpy convention of raising an error when you try to convert something to a bool. This happens in a if or when using the boolean operations, and, or, or not. It is not clear what the result of.

example

5 == pd.Series([12,2,5,10])

The result you get is a Series of booleans, equal in size to the pd.Series in the right hand side of the expression. So, you get an error. The problem here is that you are comparing a pd.Series with a value, so you’ll have multiple True and multiple False values, as in the case above. This of course is ambiguous, since the condition is neither True or False. You need to further aggregate the result so that a single boolean value results from the operation. For that you’ll have to use either any or all depending on whether you want at least one (any) or all values to satisfy the condition.

(5 == pd.Series([12,2,5,10])).all()
# False

or

(5 == pd.Series([12,2,5,10])).any()
# True