-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade visualize_graph for explain module #8743
Open
Sutongtong233
wants to merge
12
commits into
pyg-team:master
Choose a base branch
from
Sutongtong233:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c6a9f52
refine explain dataset
Sutongtong233 5c60000
refine explain dataset
Sutongtong233 a9d0c96
add GNNExplainer graph-lvel example
Sutongtong233 71b3b57
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b451a9d
Delete examples/explain/gnn_explainer_mutug.py
Sutongtong233 2b21de3
update
rusty1s c9a0d15
update
rusty1s c05c214
update
rusty1s 996fea5
update visualization
Sutongtong233 2644026
Merge branch 'pyg-team:master' into master
Sutongtong233 dbb8251
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b83559b
Merge branch 'master' into master
rusty1s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,6 +26,7 @@ def visualize_graph( | |||
edge_weight: Optional[Tensor] = None, | ||||
path: Optional[str] = None, | ||||
backend: Optional[str] = None, | ||||
**kwargs, | ||||
) -> Any: | ||||
r"""Visualizes the graph given via :obj:`edge_index` and (optional) | ||||
:obj:`edge_weight`. | ||||
|
@@ -58,7 +59,8 @@ def visualize_graph( | |||
backend = 'graphviz' if has_graphviz() else 'networkx' | ||||
|
||||
if backend.lower() == 'networkx': | ||||
return _visualize_graph_via_networkx(edge_index, edge_weight, path) | ||||
return _visualize_graph_via_networkx(edge_index, edge_weight, path, | ||||
**kwargs) | ||||
elif backend.lower() == 'graphviz': | ||||
return _visualize_graph_via_graphviz(edge_index, edge_weight, path) | ||||
|
||||
|
@@ -98,10 +100,15 @@ def _visualize_graph_via_networkx( | |||
edge_index: Tensor, | ||||
edge_weight: Tensor, | ||||
path: Optional[str] = None, | ||||
**kwargs, | ||||
) -> Any: | ||||
import matplotlib.pyplot as plt | ||||
import networkx as nx | ||||
|
||||
node_label = kwargs['node_label'] | ||||
color_dict = kwargs['color_dict'] | ||||
target_node = kwargs['target_node'] | ||||
|
||||
g = nx.DiGraph() | ||||
node_size = 800 | ||||
|
||||
|
@@ -127,10 +134,26 @@ def _visualize_graph_via_networkx( | |||
), | ||||
) | ||||
|
||||
node_color = ['white'] * len(g.nodes) | ||||
if node_label != None: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if |
||||
assert color_dict != None | ||||
node_color = [] | ||||
for i, node_id in enumerate(list(g.nodes)): | ||||
node_color.append(color_dict[int(node_label[node_id])]) | ||||
|
||||
if target_node != None: | ||||
for i, node_id in enumerate(list(g.nodes)): | ||||
if node_id == target_node: | ||||
print("kylin") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
node_color[i] = 'red' | ||||
break | ||||
|
||||
nodes = nx.draw_networkx_nodes(g, pos, node_size=node_size, | ||||
node_color='white', margins=0.1) | ||||
node_color=node_color, margins=0.1) | ||||
nodes.set_edgecolor('black') | ||||
nx.draw_networkx_labels(g, pos, font_size=10) | ||||
|
||||
if kwargs['draw_node_idx'] == True: | ||||
nx.draw_networkx_labels(g, pos, font_size=10) | ||||
|
||||
if path is not None: | ||||
plt.savefig(path) | ||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add the new arguments as optional arguemnts and add documentation for them. That way the end user is aware of the options available to them.