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 95a29958fd
Update README.rst
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
95a29958fd
Update README.rst
3 years ago
7754c4c350
Add requirements.txt
3 years ago
5b81f3c633
Add figures to README
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
  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. For the full package description go to https://test.pypi.org/project/network-graph-visualization/.
  8. And for the documentation go to the corresponding Homepage at https://network-graph-visualization.readthedocs.io/en/latest/
  9. Prerequisites
  10. -------------
  11. This package requires networkx version >= 2.5 and plotly version >=
  12. 4.14.3. See ``pyproject.toml`` for the complete prerequisites.
  13. Installation
  14. ------------
  15. Start with install the dependencies: pandas, matplotlib, networkx, plotly, Sphinx.
  16. Install the package through:
  17. ::
  18. pip install -i https://test.pypi.org/simple/ network-graph-visualization
  19. Usage
  20. -----
  21. Below is an example how to use this package. This description also shows
  22. how to add node and edge attributes to the graph from the corresponding
  23. pandas dataframes. The output will be anything similar to the below figures.
  24. .. image:: figures/Node_Attributes.png
  25. .. image:: figures/Edge_Attributes.png
  26. **Create two separate dataframes.** One with information about the nodes and
  27. one with information about the connections. For simplicity, call them
  28. ``connections_df`` and ``nodes_df``.
  29. ::
  30. connections_df = pd.read_csv(CONNECTIONS_FILENAME)
  31. nodes_df = pd.read_csv(NODES_FILENAME)
  32. **Build an empty graph.**
  33. ::
  34. G = nx.Graph()
  35. **Add edge attributes.** Create a column of connections as input for
  36. Networkx. Set these as the index, Convert dataframe to dictionary where
  37. the indices are the key and the attributes the values. Add edges and
  38. their attributes to empty graph.
  39. ::
  40. connections_df['connections'] = list(zip(connections_df['SOURCE_VARIABLE'], connections_df['TARGET_VARIABLE']))
  41. connections_temp = connections_df[['connections', 'EDGE_ATTRIBUTE_1', 'EDGE_ATTRIBUTE_2']].set_index('connections')
  42. connections_dict = connections_temp.to_dict('index')
  43. G.add_edges_from((k[0], k[1], d) for k,d in connections_dict.items())
  44. **Add node attributes.** In contrast to edge attributes node attributes can
  45. be added all at once.
  46. ::
  47. nodes_temp = nodes_df.set_index('NODE_NAME_VARIABLE')
  48. nodes_dict = nodes_temp.to_dict('index')
  49. nx.set_node_attributes(G, nodes_dict)
  50. **Call the package.**
  51. ::
  52. import network_graph_visualization.plot
  53. network_plot = network_graph_visualization.plot.GraphNetwork(G)
  54. **View graph attributes.**
  55. ::
  56. print(network_plot.G.nodes(data=True))
  57. print(network_plot.G.edges(data=True))
  58. **Optional to add all node and edge attributes as hovering text.**
  59. **Add node hover text.**
  60. ::
  61. NODE_HOVERTEXT = []
  62. for node in G.nodes():
  63. NODE_HOVERTEXT.append(
  64. "Name: " + node + "<br>" + \
  65. "NODE_ATTRIBUTE_1: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_1']) + "<br>" + \
  66. "NODE_ATTRIBUTE_2: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_2'])
  67. )
  68. **Add edge hover text.**
  69. ::
  70. EDGE_HOVERTEXT = []
  71. for edge in G.edges():
  72. EDGE_HOVERTEXT.append(
  73. "EDGE_ATTRIBUTE_1: " + str(G.edges[edge]['EDGE_ATTRIBUTE_1']) + "<br>" + \
  74. "EDGE_ATTRIBUTE_2: " + str(G.edges[edge]['EDGE_ATTRIBUTE_2'])
  75. )
  76. **Run node and edge traces.**
  77. ::
  78. network_plot.trace_nodes(node_color_variable='NODE_ATTRIBUTE_1', node_text=NODE_HOVERTEXT)
  79. network_plot.trace_edges(edge_text=EDGE_HOVERTEXT) #edge_attribute='EDGE_ATTRIBUTE_2'
  80. **Build visualization.**
  81. ::
  82. network_plot.visualization_attributes(title='TITLE OF THE PLOT')
  83. **Draw and visualize the network.**
  84. ::
  85. network_plot.draw_network(graph_filename='GRAPH_FILENAME.html')
  86. Authors and acknowledgment
  87. --------------------------
  88. Annalie Kruseman
  89. Feel free to contact me about any questions related to this package.
  90. annaliakruseman@gmail.com
  91. This package has been tested with the Stack Overflow Tag Network as posted on `Kaggle <https://www.kaggle.com/stackoverflow/stack-overflow-tag-network?select=stack_network_links.csv>`_.
Tip!

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

About

No description

Collaborators 1

Comments

Loading...