Skip to content

Incompatibility community detection and matplotlib backend #409

@svalkiers

Description

@svalkiers

Hi,

When using python-igraph's matplotlib backend, I have experienced some interoperability issues with the mark_groups functionality of the plot command. When I create a VertexClustering object (see working example) and try to visualize its groups without additional markup, everything works fine and I get a clean output as shown in the figure below.

# WORKING EXAMPLE

import igraph as ig
import matplotlib.pyplot as plt
import random

random.seed(42)

visual_style = {}

g = ig.Graph.Erdos_Renyi(20,0.2)
communities = g.community_multilevel()
graph_layout = g.layout("kk")

visual_style["vertex_size"] = 10
# visual_style["vertex_color"] = "red"
visual_style["layout"] = graph_layout

fig, ax = plt.subplots()

ig.plot(communities,
        mark_groups=True,
        target=ax,
        **visual_style)

image

However, when I try to add vertex color to the visual_style dictionary (i.e. uncomment line 16) , I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-77-bab2d710ea9e> in <module>
     19 fig, ax = plt.subplots()
     20 
---> 21 ig.plot(communities,
     22         mark_groups=True,
     23         target=ax,

~/miniconda3/envs/immuno/lib/python3.9/site-packages/igraph/drawing/__init__.py in plot(obj, target, bbox, *args, **kwds)
    480     if hasattr(plt, "Axes") and isinstance(target, plt.Axes):
    481         result = MatplotlibGraphDrawer(ax=target)
--> 482         result.draw(obj, *args, **kwds)
    483         return
    484 

~/miniconda3/envs/immuno/lib/python3.9/site-packages/igraph/drawing/graph.py in draw(self, graph, *args, **kwds)
   1079         # Mark groups
   1080         if "mark_groups" in kwds:
-> 1081             for idx, color in kwds["mark_groups"].items():
   1082                 points = [vcoord[i] for i in idx]
   1083                 vertices = np.asarray(convex_hull(points, coords=True))

AttributeError: 'bool' object has no attribute 'items'

When using the regular plotting route, you can change the vertex color while marking the communities with the shaded area. Is this also possible with the matplotlib backend in any sort of way?

Version information

# Name                    Version                   Build  Channel
python-igraph             0.9.1            py39hfef886c_0    conda-forge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions