Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Integration:  git github
Annalie Kruseman 50acf73d0d
Modify readme
3 years ago
50acf73d0d
Modify readme
3 years ago
cb3a113c89
Modify pyproject.toml
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
c360058af6
Publish package on TestPyPI
3 years ago
a2f31fb93f
Initialize git
3 years ago
50acf73d0d
Modify readme
3 years ago
c360058af6
Publish package on TestPyPI
3 years ago
50acf73d0d
Modify readme
3 years ago
Storage Buckets

README.rst

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  1. Introduction
  2. ------------
  3. This package creates a visualization of a network graph built with
  4. Networkx with hovering functions by Plotly.
  5. Multiple node and edge attributes can be added to the network and shown
  6. in the visualization.
  7. Prerequisites
  8. -------------
  9. This package requires networkx version >= 2.5 and plotly version >=
  10. 4.14.3. See ``pyproject.toml`` for the complete prerequisites.
  11. Installation
  12. ------------
  13. Start with install the dependencies: pandas, matplotlib, networkx, plotly, Sphinx.
  14. Install the package through:
  15. ::
  16. pip install -i https://test.pypi.org/simple/ network-graph-visualization
  17. Usage
  18. -----
  19. Below is an example how to use this package. This description also shows
  20. how to add node and edge attributes to the graph from the corresponding
  21. pandas dataframes.
  22. **Create two separate dataframes.** One with information about the nodes and
  23. one with information about the connections. For simplicity, call them
  24. ``connections_df`` and ``nodes_df``.
  25. ::
  26. connections_df = pd.read_csv(CONNECTIONS_FILENAME)
  27. nodes_df = pd.read_csv(NODES_FILENAME)
  28. **Build an empty graph.**
  29. ::
  30. G = nx.Graph()
  31. **Add edge attributes.** Create a column of connections as input for
  32. Networkx. Set these as the index, Convert dataframe to dictionary where
  33. the indices are the key and the attributes the values. Add edges and
  34. their attributes to empty graph.
  35. ::
  36. connections_df['connections'] = list(zip(connections_df['SOURCE_VARIABLE'], connections_df['TARGET_VARIABLE']))
  37. connections_temp = connections_df[['connections', 'EDGE_ATTRIBUTE_1', 'EDGE_ATTRIBUTE_2']].set_index('connections')
  38. connections_dict = connections_temp.to_dict('index')
  39. G.add_edges_from((k[0], k[1], d) for k,d in connections_dict.items())
  40. **Add node attributes.** In contrast to edge attributes node attributes can
  41. be added all at once.
  42. ::
  43. nodes_temp = nodes_df.set_index('NODE_NAME_VARIABLE')
  44. nodes_dict = nodes_temp.to_dict('index')
  45. nx.set_node_attributes(G, nodes_dict)
  46. **Call the package.**
  47. ::
  48. import network_graph_visualization.plot
  49. network_plot = plot.GraphNetwork(G)
  50. **View graph attributes.**
  51. ::
  52. print(network_plot.G.nodes(data=True))
  53. print(network_plot.G.edges(data=True))
  54. **Optional to add all node and edge attributes as hovering text.**
  55. **Add node hover text.**
  56. ::
  57. NODE_HOVERTEXT = []
  58. for node in G.nodes():
  59. NODE_HOVERTEXT.append(
  60. "Name: " + node + "<br>" + \
  61. "NODE_ATTRIBUTE_1: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_1']) + "<br>" + \
  62. "NODE_ATTRIBUTE_2: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_2'])
  63. )
  64. **Add edge hover text.**
  65. ::
  66. EDGE_HOVERTEXT = []
  67. for edge in G.edges():
  68. EDGE_HOVERTEXT.append(
  69. "EDGE_ATTRIBUTE_1: " + str(G.edges[edge]['EDGE_ATTRIBUTE_1']) + "<br>" + \
  70. "EDGE_ATTRIBUTE_2: " + str(G.edges[edge]['EDGE_ATTRIBUTE_2'])
  71. )
  72. **Run node and edge traces.**
  73. ::
  74. network_plot.trace_nodes(node_color_variable='NODE_ATTRIBUTE_1', node_text=NODE_HOVERTEXT)
  75. network_plot.trace_edges(edge_text=EDGE_HOVERTEXT) #edge_attribute='EDGE_ATTRIBUTE_2'
  76. **Build visualization.**
  77. ::
  78. network_plot.visualization_attributes(title='TITLE OF THE PLOT')
  79. **Draw and visualize the network.**
  80. ::
  81. network_plot.draw_network(graph_filename='GRAPH_FILENAME.html')
Tip!

Press p or to see the previous file or, n or to see the next file

About

No description

Collaborators 1

Comments

Loading...