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 21f256b8c1
Add figures to README
3 years ago
aa8c4bd39a
Add requirements.txt
3 years ago
08a4120d73
Add figures to README
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a8db064116
Add figures to README
3 years ago
927772a61a
Modify .gitignore
3 years ago
a2f31fb93f
Initialize git
3 years ago
21f256b8c1
Add figures to README
3 years ago
7754c4c350
Add requirements.txt
3 years ago
65b34eec0e
Change version
3 years ago
7754c4c350
Add requirements.txt
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  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. The output will be anything similar to the below figures.
  22. |pic1| any text |pic2|
  23. .. image:: figures/Node_Attributes.png
  24. :width: 45%
  25. .. image:: figures/Edge_Attributes.png
  26. :width: 45%
  27. sdfsadf
  28. .. image:: figures/Node_Attributes.png
  29. :width: 45 %
  30. .. image:: figures/Edge_Attributes.png
  31. :width: 45 %
  32. **Create two separate dataframes.** One with information about the nodes and
  33. one with information about the connections. For simplicity, call them
  34. ``connections_df`` and ``nodes_df``.
  35. ::
  36. connections_df = pd.read_csv(CONNECTIONS_FILENAME)
  37. nodes_df = pd.read_csv(NODES_FILENAME)
  38. **Build an empty graph.**
  39. ::
  40. G = nx.Graph()
  41. **Add edge attributes.** Create a column of connections as input for
  42. Networkx. Set these as the index, Convert dataframe to dictionary where
  43. the indices are the key and the attributes the values. Add edges and
  44. their attributes to empty graph.
  45. ::
  46. connections_df['connections'] = list(zip(connections_df['SOURCE_VARIABLE'], connections_df['TARGET_VARIABLE']))
  47. connections_temp = connections_df[['connections', 'EDGE_ATTRIBUTE_1', 'EDGE_ATTRIBUTE_2']].set_index('connections')
  48. connections_dict = connections_temp.to_dict('index')
  49. G.add_edges_from((k[0], k[1], d) for k,d in connections_dict.items())
  50. **Add node attributes.** In contrast to edge attributes node attributes can
  51. be added all at once.
  52. ::
  53. nodes_temp = nodes_df.set_index('NODE_NAME_VARIABLE')
  54. nodes_dict = nodes_temp.to_dict('index')
  55. nx.set_node_attributes(G, nodes_dict)
  56. **Call the package.**
  57. ::
  58. import network_graph_visualization.plot
  59. network_plot = plot.GraphNetwork(G)
  60. **View graph attributes.**
  61. ::
  62. print(network_plot.G.nodes(data=True))
  63. print(network_plot.G.edges(data=True))
  64. **Optional to add all node and edge attributes as hovering text.**
  65. **Add node hover text.**
  66. ::
  67. NODE_HOVERTEXT = []
  68. for node in G.nodes():
  69. NODE_HOVERTEXT.append(
  70. "Name: " + node + "<br>" + \
  71. "NODE_ATTRIBUTE_1: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_1']) + "<br>" + \
  72. "NODE_ATTRIBUTE_2: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_2'])
  73. )
  74. **Add edge hover text.**
  75. ::
  76. EDGE_HOVERTEXT = []
  77. for edge in G.edges():
  78. EDGE_HOVERTEXT.append(
  79. "EDGE_ATTRIBUTE_1: " + str(G.edges[edge]['EDGE_ATTRIBUTE_1']) + "<br>" + \
  80. "EDGE_ATTRIBUTE_2: " + str(G.edges[edge]['EDGE_ATTRIBUTE_2'])
  81. )
  82. **Run node and edge traces.**
  83. ::
  84. network_plot.trace_nodes(node_color_variable='NODE_ATTRIBUTE_1', node_text=NODE_HOVERTEXT)
  85. network_plot.trace_edges(edge_text=EDGE_HOVERTEXT) #edge_attribute='EDGE_ATTRIBUTE_2'
  86. **Build visualization.**
  87. ::
  88. network_plot.visualization_attributes(title='TITLE OF THE PLOT')
  89. **Draw and visualize the network.**
  90. ::
  91. network_plot.draw_network(graph_filename='GRAPH_FILENAME.html')
  92. Authors and acknowledgment
  93. --------------------------
  94. Annalie Kruseman
  95. Feel free to contact me about any questions related to this package.
  96. annaliakruseman@gmail.com
Tip!

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

About

No description

Collaborators 1

Comments

Loading...