nx2vos: export networkx graphs to VOSviewer format
Project description
nx2vos
nx2vos is a simple Python library that exports networkx graphs to the VOSviewer format.
Installation
Install with pip
:
pip install nx2vos
Usage
Basic usage
Using nx2vos, you can write a networkx graph to VOSviewer map and network files. From the VOSviewer manual:
- A map file is a text file that contains information about the items in a map. Items are characterized by a number of attributes.
- A network file is a text file that contains information about the links between the items in a map. A network file specifies which pairs of items are connected by a link. It also specifies the strength of each link.
Typically, you want to save both the map and network file:
import networkx as nx
import nx2vos
# Create example network
G = nx.Graph()
G.add_weighted_edges_from([("a", "b", 1), ("b", "c", 2), ("a", "c", 3)])
# Save map and network files to map.txtx and network.txt
nx2vos.write_vos_map(G, "map.txt")
nx2vos.write_vos_network(G, "network.txt")
Visualize the result in VOSviewer by clicking Create...
in the File
tab on the left. Choose Create a map based on network data
and point VOSviewer to your map and network file. In the following screens, you can adjust the map by, for instance, excluding certain nodes or edges. After clicking Finish
, the resulting map is shown.
Node attributes
You can instruct nx2vos which attribute on the networkx side corresponds to which attribute on the VOSviewer side. Let's look at an example, building on the previous code snippet:
# Calculate Pagerank and add as node attribute
pr = nx.pagerank(G)
for n, val in pr.items():
G.nodes[n]["pagerank"] = val
# Add example description to each node. Can include HTML formatting.
for n in G:
G.nodes[n]["text"] = f"This is node <b>{n}</b>."
# Write to file, including attribute data
nx2vos.write_vos_map(
G, "map2.txt", description_attr="text", weight_attrs=["pagerank"]
)
The description will be shown on hover in VOSviewer. The weight can be used in the visualization to display items with higher weight more prominently.
This table shows all supported VOSviewer attributes:
VOSviewer attribute | Specify with... | Value (if not None ) |
---|---|---|
sublabel |
sublabel_attr |
string (attribute name) |
description |
description_attr |
string (attribute name) |
url |
url_attr |
string (attribute name) |
x |
x_attr (use together with y_attr ) |
string (attribute name) |
y |
y_attr (use together with x_attr ) |
string (attribute name) |
cluster |
cluster_attr |
string (attribute name) |
weight |
weight_attrs |
list of strings (attribute names) |
score |
score_attrs |
list of strings (attribute names) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nx2vos-0.1.tar.gz
.
File metadata
- Download URL: nx2vos-0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e035f133cd7e0fc5c6170a379abccb362284792b79d379e89e8e4ca5bb4914c |
|
MD5 | 6a8c922cd027ddb3f389783b80e5a4db |
|
BLAKE2b-256 | 9861fbcb45144bc2ab20d517b3775447c2a2ca1a88baf28b58f6b7bc4020bc37 |
File details
Details for the file nx2vos-0.1-py3-none-any.whl
.
File metadata
- Download URL: nx2vos-0.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 532016280905abfa5ca65fbe03ad518e6b1194d6b13dc6bab75975368b8ecfd2 |
|
MD5 | 29fc5ae54cf86274998182991b67d455 |
|
BLAKE2b-256 | 8c3f611580400179dedcd5225e8c632d0c9c4d41c87181c86d850f5a2cc9a566 |