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 a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
3 years ago
a2f31fb93f
Initialize git
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
  1. This package creates a visualization of a network graph built with
  2. Networkx with hovering functions by Plotly.
  3. Multiple node and edge attributes can be added to the network and shown
  4. in the visualization.
  5. Prerequisites
  6. -------------
  7. This package requires networkx version >= 2.5 and plotly version >=
  8. 4.14.3. See ``pyproject.toml`` for the complete prerequisites.
  9. Installation
  10. ------------
  11. Install the package through
  12. ::
  13. test
  14. Usage
  15. -----
  16. Below is an example how to use this package. This description also shows
  17. how to add node and edge attributes to the graph from the corresponding
  18. pandas dataframes.
  19. **Create two separate dataframes.** One with information about the nodes and
  20. one with information about the connections. For simplicity, call them
  21. ``connections_df`` and ``nodes_df``.
  22. ::
  23. connections_df = pd.read_csv(CONNECTIONS_FILENAME)
  24. nodes_df = pd.read_csv(NODES_FILENAME)
  25. **Build an empty graph.**
  26. ::
  27. G = nx.Graph()
  28. **Add edge attributes.** Create a column of connections as input for
  29. Networkx. Set these as the index, Convert dataframe to dictionary where
  30. the indices are the key and the attributes the values. Add edges and
  31. their attributes to empty graph.
  32. ::
  33. connections_df['connections'] = list(zip(connections_df['SOURCE_VARIABLE'], connections_df['TARGET_VARIABLE']))
  34. connections_temp = connections_df[['connections', 'EDGE_ATTRIBUTE_1', 'EDGE_ATTRIBUTE_2']].set_index('connections')
  35. connections_dict = connections_temp.to_dict('index')
  36. G.add_edges_from((k[0], k[1], d) for k,d in connections_dict.items())
  37. **Add node attributes.** In contrast to edge attributes node attributes can
  38. be added all at once.
  39. ::
  40. nodes_temp = nodes_df.set_index('NODE_NAME_VARIABLE')
  41. nodes_dict = nodes_temp.to_dict('index')
  42. nx.set_node_attributes(G, nodes_dict)
  43. **Call the package.**
  44. ::
  45. import plot
  46. network_plot = plot.GraphNetwork(G)
  47. **View graph attributes.**
  48. ::
  49. print(network_plot.G.nodes(data=True))
  50. print(network_plot.G.edges(data=True))
  51. **Optional to add all node and edge attributes as hovering text.**
  52. **Add node hover text.**
  53. ::
  54. NODE_HOVERTEXT = []
  55. for node in G.nodes():
  56. NODE_HOVERTEXT.append(
  57. "Name: " + node + "<br>" + \
  58. "NODE_ATTRIBUTE_1: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_1']) + "<br>" + \
  59. "NODE_ATTRIBUTE_2: " + str(network_plot.G.nodes[node]['NODE_ATTRIBUTE_2'])
  60. )
  61. **Add edge hover text.**
  62. ::
  63. EDGE_HOVERTEXT = []
  64. for edge in G.edges():
  65. EDGE_HOVERTEXT.append(
  66. "EDGE_ATTRIBUTE_1: " + str(G.edges[edge]['EDGE_ATTRIBUTE_1']) + "<br>" + \
  67. "EDGE_ATTRIBUTE_2: " + str(G.edges[edge]['EDGE_ATTRIBUTE_2'])
  68. )
  69. **Run node and edge traces.**
  70. ::
  71. network_plot.trace_nodes(node_color_variable='NODE_ATTRIBUTE_1', node_text=NODE_HOVERTEXT)
  72. network_plot.trace_edges(edge_text=EDGE_HOVERTEXT) #edge_attribute='EDGE_ATTRIBUTE_2'
  73. **Build visualization.**
  74. ::
  75. network_plot.visualization_attributes(title='TITLE OF THE PLOT')
  76. **Draw and visualize the network.**
  77. ::
  78. 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...