Skip to main content

pvsvg

Introduction

a python wrapper of the vis.js network visualization library with an additional ability to export static SVG.

Inspired by the excellent python library pyvis but I required a function to export the resulting network as a static SVG.

The code for exporting the SVG is taken from justinharrell/vis-svg.

Installation

You can install this via pip:

pip install pvsvg

Usage

This library exposes a single class ( Network ) which takes as input a networkx Graph.

All the configuration for node and edge level attributes (like color, size, mass) are passed transparently to vis.js so you can configure your resulting network via the attributes of your networkx nodes and edges respectively.

You can see node level configuration and edge level configuration on the vis.js documentation.

Exporting as SVG

The resulting HTML file will have some configuration buttons built-in. One of these is the export-svg button which will generate the static SVG and write it to a file (network.svg)

Keep in mind that it will write the SVG of whatever is within the Canvas element at the time. Essentially the view you have within the boundaries of the Canvas is exactly what will be written to the SVG.

Note: Currently the node borders are not being written to the SVG. Besides that everything else should appear.

Example

from pvsvg import Network
import networkx as nx

# generate some random graph
g = nx.fast_gnp_random_graph(15, 0.2)

# set node level attributes
for n in g.nodes(data=True):
    id = n[0]
    if id % 2 == 0:
        n[1]["color"] = "red"
    else:
        n[1]["color"] = "blue"

    if id % 3 == 0:
        n[1]["shape"] = "square"
    else:
        n[1]["shape"] = "dot"

    n[1]["label"] = f"Node {id}"
    n[1]["title"] = f"Node {id} has color {n[1]['color']} and shape {n[1]['shape']}"
    n[1]["size"] = (id + 1)

# set edge level attributes
for e in g.edges(data=True):
    e[2]["color"] = {
        "color": "black",
        "inherit": False,
    }

# Instantiate the network
n = Network(g, width=1200)

# Draw the network as an html
n.draw("test.html")

Release files for pvsvg 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pvsvg 0.1.3
File Size Uploaded
pvsvg-0.1.3.tar.gz 405.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pvsvg 0.1.3
File Interpreter ABI Platform
pvsvg-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 815.1 kB

Release files / pvsvg-0.1.3.tar.gz

Download URL pvsvg-0.1.3.tar.gz
Size 405.5 kB
Tags Source
SHA-256 checksum
How to use checksums
80b39239923b52bccc470c78a521438ace12b9d6afb114b05240e346ddcab024
BLAKE2b-256 checksum
How to use checksums
0f4ad8ee1944828c58ee4de87667e23bcc38f3fcb9d944d55993c0ba9fb392b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/23.0.0

Release files / pvsvg-0.1.3-py3-none-any.whl

Download URL pvsvg-0.1.3-py3-none-any.whl
Size 409.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bad0069c1d00fb1ee839420347ede03c363c453c22dd560bfac574b6ef1fbf05
BLAKE2b-256 checksum
How to use checksums
bcf77d53b35d3b9bf1d3425effdbf00b057959af6ae4aa5d6f136309082b0139
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/23.0.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page