Package: nx2vos
nx2vosnx2vos is a simple Python library that exportsnetworkxgraphs or networks to theVOSviewerformat.InstallationInstall withpip:pip install nx2vosUsageUsing nx2vos, you can write a networkx graph toVOSviewer map and network filesor to aVOSviewer JSON file.Map and network filesOriginally, VOSviewer saved data in so-called map and network files:Amap filecontains information about the items (i.e., nodes) in a VOSviewer map. Items can be characterized by a number of attributes.Anetwork filecontains 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:importnetworkxasnximportnx2vos# Create example networkG=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.txtnx2vos.write_vos_map(G,"map.txt")nx2vos.write_vos_network(G,"network.txt")To visualize the result in VOSviewer, clickCreate...in theFiletab on the left. ChooseCreate a map based on network dataand 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 clickingFinish, the resulting map is shown.JSON filesMore 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:importnetworkxasnximportnx2vos# Create example networkG=nx.Graph()G.add_weighted_edges_from([("a","b",1),("b","c",2),("a","c",3)])# Save graph to JSONnx2vos.write_vos_json(G,"graph.json")To visualize the result in VOSviewer, clickCreate...in theFiletab on the left. ChooseCreate a map based on network dataand point VOSviewer to your JSON file. In the following screens, you can adjust the map by, for instance, excluding certain nodes or edges. After clickingFinish, 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 attributesYou 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 attributepr=nx.pagerank(G)forn,valinpr.items():G.nodes[n]["pagerank"]=val# Add example description to each node. Can include HTML formatting.forninG: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 attributeSpecify with...Value (if notNone)sublabelsublabel_attrstring (attribute name)descriptiondescription_attrstring (attribute name)urlurl_attrstring (attribute name)xx_attr(use together withy_attr)string (attribute name)yy_attr(use together withx_attr)string (attribute name)clustercluster_attrstring (attribute name)weightorweightsweight_attrslist of strings (attribute names)scoreorscoresscore_attrslist of strings (attribute names)