-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation (mostly VISUALIZATION and COOKBOOK)
- Loading branch information
Showing
14 changed files
with
253 additions
and
100 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,86 @@ | ||
Visualize Groups | ||
---------------- | ||
Simplest use case | ||
----------------- | ||
|
||
Cluster a network and visualize it with groups. | ||
Given a *networkx.Graph* object, you can launch netwulf like so: | ||
|
||
.. code:: python | ||
import networkx as nx | ||
import netwulf as wulf | ||
G = nx.barabasi_albert_graph(100, 2) | ||
wulf.visualize(G) # <-- THIS IS IT | ||
Alternatively, *netwulf.visualize* can accept a node-link dictionary object `formatted like this <https://gist.githubusercontent.com/ulfaslak/6be66de1ac3288d5c1d9452570cbba5a/raw/4cab5036464800e51ce59fc088688e9821795efb/miserables.json>`_. | ||
|
||
|
||
Node and link attributes | ||
------------------------ | ||
|
||
Netwulf recognizes node attributes 'group' and 'size', and link attribute 'weight'. | ||
Users can create a *networkx.Graph* object with node and link data: | ||
|
||
.. code:: python | ||
list(G.nodes(data=True))[:3] | ||
# [(0, {'group': 0, 'size': 0.20982489558943607}), | ||
# (1, {'group': 0, 'size': 0.7118952904573288}), | ||
# (2, {'group': 0, 'size': 0.8785902846905586})] | ||
list(G.edges(data=True))[:3] | ||
# [(0, 5, {'weight': 0.8917083938103719}), | ||
# (0, 9, {'weight': 0.29583879684946757}), | ||
# (0, 12, {'weight': 0.36847140599448236})] | ||
Example: | ||
|
||
.. code:: python | ||
import numpy as np | ||
import networkx as nx | ||
import community | ||
import netwulf as wulf | ||
G = nx.random_partition_graph([10,10,10],.25,.01) | ||
bb = community.best_partition(G) # dict of node-community pairs | ||
nx.set_node_attributes(G, bb, 'group') | ||
# Create a network | ||
G = nx.random_partition_graph([10, 10, 10], .25, .01) | ||
# Change 'block' node attribute to 'group' | ||
for k, v in G.nodes(data=True): | ||
v['group'] = v['block']; del v['block'] | ||
# Or detect communities and encode them in 'group' attribute | ||
# import community | ||
# bb = community.best_partition(G) | ||
# nx.set_node_attributes(G, bb, 'group') | ||
# Set node 'size' attributes | ||
for n, data in G.nodes(data=True): | ||
n['size'] = np.random.random() | ||
# Set link 'weight' attributes | ||
for n1, n2, data in G.edges(data=True): | ||
data['weight'] = np.random.random() | ||
wulf.visualize(G) | ||
.. figure:: img/random_partition_graph.png | ||
|
||
colored partition | ||
Note: If 'group' is not a color (like "red" or "#4fba21") the group colors are assigned randomly. | ||
|
||
|
||
Save as PDF | ||
----------- | ||
|
||
.. code:: python | ||
import networkx as nx | ||
import netwulf as wulf | ||
G = nx.barabasi_albert_graph(100, 2) | ||
network, config = wulf.visualize(G, plot_in_cell_below=False) | ||
fig, ax = plt.subplots(figsize=(10, 10)) | ||
wulf.draw_netwulf(network, fig, ax) | ||
plt.savefig("myfigure.pdf") |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.