Skip to content

TypeError: draw_networkx_nodes() got an unexpected keyword argument 'with_labels' #242

Description

@derrick710

I am trying to recreate the GNNExplainer on Google Colab using the example xgraph_code_tutorial.ipynb. Everything works great until I try to visualize the graph. Thank you for your help

sparsity = 0.7
import matplotlib.pyplot as plt

# Visualization
gnnexplainer_related_preds = \
    gnnexplainer(data.x, data.edge_index, sparsity=sparsity, num_classes=num_classes, node_idx=node_idx)
ax, G = gnnexplainer.visualize_graph(node_idx=node_idx,
                                     edge_index=data.edge_index,
                                     edge_mask=gnnexplainer_related_preds[1][prediction],
                                     y=data.y)
plt.show()


TypeError                                 Traceback (most recent call last)
[<ipython-input-8-413a9bd50c1c>](https://localhost:8080/#) in <cell line: 7>()
      5 gnnexplainer_related_preds = \
      6     gnnexplainer(data.x, data.edge_index, sparsity=sparsity, num_classes=num_classes, node_idx=node_idx)
----> 7 ax, G = gnnexplainer.visualize_graph(node_idx=node_idx,
      8                                      edge_index=data.edge_index,
      9                                      edge_mask=gnnexplainer_related_preds[1][prediction],

[/usr/local/lib/python3.10/dist-packages/dig/xgraph/method/base_explainer.py](https://localhost:8080/#) in visualize_graph(self, node_idx, edge_index, edge_mask, y, threshold, nolabel, **kwargs)
    240                     connectionstyle="arc3,rad=0.08",  # rad control angle
    241                 ))
--> 242         nx.draw_networkx_nodes(G, pos, node_color=node_colors, **kwargs)
    243         # define node labels
    244         if self.molecule:

TypeError: draw_networkx_nodes() got an unexpected keyword argument 'with_labels'

Activity

  1. Moses14159 commented on May 26, 2024

    @Moses14159

    I also have this problem

  2. nicolasguillard commented on Aug 30, 2024

    @nicolasguillard

    The draw_networkx_nodes() function doesn't accept any more extra argument (and with_labels is not a regular one) since version 2.5 of NetworkX. I tried to install version 2.4 but I got a depency issue, trying to run the notebook in Colab. I have sourced the bug, so I am trying to fix it then submit a pull request, and to provide an alternative way to install the fix meanwhile.

  3. nicolasguillard commented on Sep 7, 2024

    @nicolasguillard

    Hi,

    You can install the last release + bug fix from the sources of my fork until the pull request is approved and the 1.1.1 release is provided to pypi, following the instructions (inspired from the DIG installation from source procedure )

    Locally, in a virtual env (recommanded) :

    git clone --branch Main_111_hotfix_issue_242 https://github.com/nicolasguillard/DIG.git
    pip -q install ./DIG
    

    In Google Colab :

    !git clone --branch Main_111_hotfix_issue_242 https://github.com/nicolasguillard/DIG.git
    !pip -q install ./DIG
    

    Let me know if you have any new issue.

    Regards.

  4. added a commit that references this issue on Sep 7, 2024
  5. nicolasguillard commented on Sep 8, 2024

    @nicolasguillard

    In addition, if you are using the dig-stable version, you can install the sources including bug fix #242 by following these instructions :

    Locally, in a virtual env (recommanded) :

    git clone --branch bugfix_issue_242 https://github.com/nicolasguillard/DIG.git
    pip -q install ./DIG
    

    In Google Colab :

    !git clone --branch bugfix_issue_242 https://github.com/nicolasguillard/DIG.git
    !pip -q install ./DIG
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions