Skip to main content

nx2vos: export networkx graphs to VOSviewer format

Project description

nx2vos

nx2vos is a simple Python library that exports networkx graphs or networks to the VOSviewer format.

Installation

Install with pip:

pip install nx2vos

Usage

Using nx2vos, you can write a networkx graph to VOSviewer map and network files or to a VOSviewer JSON file.

Map and network files

Originally, VOSviewer saved data in so-called map and network files:

  • A map file contains information about the items (i.e., nodes) in a VOSviewer map. Items can be characterized by a number of attributes.
  • A network file contains information about the links between the items in a map. A network file specifies which pairs of items are connected, as well as 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.txt and network.txt
nx2vos.write_vos_map(G, "map.txt")
nx2vos.write_vos_network(G, "network.txt")

To visualize the result in VOSviewer, click 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.

JSON files

More recently, VOSviewer also supports a JSON file format, which contais both data on items and the links between them. In other words, one JSON file can replace both a map and network file.

To save:

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 graph to JSON
nx2vos.write_vos_json(G, "graph.json")

To visualize the result in VOSviewer, click Create... in the File tab on the left. Choose Create a map based on network data and point VOSviewer to your JSON 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.

VOSviewer JSON files can also store configuration of the visualization, such as color scheme or parameters of the VOS algorithm. This is not currently supported by nx2vos.

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 map file, including attribute data:
nx2vos.write_vos_map(
    G, "map2.txt", description_attr="text", weight_attrs=["pagerank"]
)
# Or write to JSON, including attribute data:
nx2vos.write_vos_json(
    G, "graph2.json", 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 or weights weight_attrs list of strings (attribute names)
score or scores score_attrs list of strings (attribute names)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nx2vos-0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

nx2vos-0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file nx2vos-0.2.tar.gz.

File metadata

  • Download URL: nx2vos-0.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for nx2vos-0.2.tar.gz
Algorithm Hash digest
SHA256 2a634c33c9b046b8c59a83020dfd84c33d379d26392e2a98ca6f1eaef5a9b503
MD5 e296c614765ac5e063db639345e1f3bb
BLAKE2b-256 c698a333d0b3e7ce92cf2932f4561cf6270670589dbe204287220dda64d0a79f

See more details on using hashes here.

File details

Details for the file nx2vos-0.2-py3-none-any.whl.

File metadata

  • Download URL: nx2vos-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for nx2vos-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 57c534008946a6a1df439cdec7008e3ba3e14cbe512e7cc58bd50441e6dd0dd4
MD5 566563a9770267177ea747aa15c8a57f
BLAKE2b-256 8070f70382199d6c475f55b67393cc70c137bc67ffd59d2460ff78e4918ee130

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page