Skip to content
This repository was archived by the owner on Nov 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python

matrix:
include:
- python: 2.7
- python: 3.5
- python: 3.6
- python: 3.7
dist: xenial
sudo: true

# command to install dependencies
install: pip install tox-travis

# command to run tests
script: tox
113 changes: 70 additions & 43 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,89 @@ Pyveplot
A nice way of visualizing complex networks are `Hiveplots <http://www.hiveplot.com/>`_.


This library uses `svgwrite <http://svgwrite.readthedocs.org/en/latest/classes/shapes.html>`_ to
This library uses `svgwrite <http://svgwrite.readthedocs.org/en/latest/classes/shapes.html>`_ to
programmatically create images like this one:

.. image:: https://github.com/CSB-IG/pyveplot/raw/master/example.png
.. image:: examples/example.png

Pyveplot is tested on pythons 2.7 and 3.5+

A short example
---------------
A short, modern example
-----------------------

Create a plot from a network, randomly selecting whichever axis to place 50 nodes.::
Create a plot from a network, randomly selecting whichever axis to place 50 nodes.

.. code-block:: python

import random
from math import pi
from pyveplot import Hiveplot
import networkx

random.seed(1)

from pyveplot import *
import networkx, random

# a network
g = networkx.barabasi_albert_graph(50, 2)

g = networkx.barabasi_albert_graph(50, 2, seed=2)

# numbers use px units
center = (200, 200)
# our hiveplot object
h = Hiveplot( 'short_example.svg')
# start end
axis0 = Axis( (200,200), (200,100), stroke="grey")
axis1 = Axis( (200,200), (300,300), stroke="blue")
axis2 = Axis( (200,200), (10,310), stroke="black")

h.axes = [ axis0, axis1, axis2 ]

h = Hiveplot("modern_example.svg", center=center)

axis0 = h.add_axis(start=center, end=(200, 100), stroke="grey")
# polar coordinates (radius, angle): defaults to radians
circle = 2 * pi
# str units are interpreted correctly
axis1 = h.add_axis_polar(end=("105pt", circle / 3), stroke="blue")
axis2 = h.add_axis_polar(end=("5.82cm", 240), use_radians=False, stroke="black")

# randomly distribute nodes in axes
for n in g.nodes():
node = Node(n)
random.choice( h.axes ).add_node( node, random.random() )

random.choice(h.axes).add_node(n, random.random())

for e in g.edges():
if (e[0] in axis0.nodes) and (e[1] in axis1.nodes): # edges from axis0 to axis1
h.connect(axis0, e[0], 45,
axis1, e[1], -45,
stroke_width='0.34', stroke_opacity='0.4',
stroke='purple')
elif (e[0] in axis0.nodes) and (e[1] in axis2.nodes): # edges from axis0 to axis2
h.connect(axis0, e[0], -45,
axis2, e[1], 45,
stroke_width='0.34', stroke_opacity='0.4',
stroke='red')
elif (e[0] in axis1.nodes) and (e[1] in axis2.nodes): # edges from axis1 to axis2
h.connect(axis1, e[0], 15,
axis2, e[1], -15,
stroke_width='0.34', stroke_opacity='0.4',
stroke='magenta')

if (e[0] in axis0.nodes) and (e[1] in axis1.nodes): # edges from axis0 to axis1
h.connect(
axis0,
e[0],
45,
axis1,
e[1],
-45,
stroke_width="0.34",
stroke_opacity="0.4",
stroke="purple",
)
elif (e[0] in axis0.nodes) and (e[1] in axis2.nodes): # edges from axis0 to axis2
h.connect(
axis0,
e[0],
-45,
axis2,
e[1],
45,
stroke_width="0.34",
stroke_opacity="0.4",
stroke="red",
)
elif (e[0] in axis1.nodes) and (e[1] in axis2.nodes): # edges from axis1 to axis2
h.connect(
axis1,
e[0],
15,
axis2,
e[1],
-15,
stroke_width="0.34",
stroke_opacity="0.4",
stroke="magenta",
)

h.save()

.. image:: examples/modern_example.png

.. image:: https://github.com/CSB-IG/pyveplot/raw/master/short_example.png

The more elaborate `example.py <https://github.com/CSB-IG/pyveplot/blob/master/example.py>`_
The more elaborate `example.py <examples/example.py>`_
shows how to use shapes for nodes, placement of the control points and attributes of edges, and the attributes
of axes.

Expand All @@ -67,6 +96,4 @@ Installation

Install library, perhaps within a virtualenv::

$ pip install pyveplot


pip install pyveplot
4 changes: 2 additions & 2 deletions example_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
a2_color = Color('#5a004c')
a3_color = Color('#336699')
# place nodes on axes
print "place nodes on axes"
print("place nodes on axes")
for n,d in sorted_dg:
nd = Node(n)

Expand Down Expand Up @@ -222,5 +222,5 @@
fill='none')


print "writing file"
print("writing file")
h.save()
File renamed without changes
File renamed without changes.
Binary file added examples/modern_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions examples/modern_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Produces a plot visually the same as short_example, but uses modern features"""
from __future__ import absolute_import, division, unicode_literals, print_function
import random
from math import pi
from pyveplot import Hiveplot
import networkx

random.seed(1)

# a network
g = networkx.barabasi_albert_graph(50, 2, seed=2)

# numbers use px units
center = (200, 200)
# our hiveplot object
h = Hiveplot("modern_example.svg", center=center)

axis0 = h.add_axis(start=center, end=(200, 100), stroke="grey")
# polar coordinates (radius, angle): defaults to radians
circle = 2 * pi
# str units are interpreted correctly
axis1 = h.add_axis_polar(end=("105pt", circle / 3), stroke="blue")
axis2 = h.add_axis_polar(end=("5.82cm", 240), use_radians=False, stroke="black")

# randomly distribute nodes in axes
for n in g.nodes():
random.choice(h.axes).add_node(n, random.random())

for e in g.edges():
if (e[0] in axis0.nodes) and (e[1] in axis1.nodes): # edges from axis0 to axis1
h.connect(
axis0,
e[0],
45,
axis1,
e[1],
-45,
stroke_width="0.34",
stroke_opacity="0.4",
stroke="purple",
)
elif (e[0] in axis0.nodes) and (e[1] in axis2.nodes): # edges from axis0 to axis2
h.connect(
axis0,
e[0],
-45,
axis2,
e[1],
45,
stroke_width="0.34",
stroke_opacity="0.4",
stroke="red",
)
elif (e[0] in axis1.nodes) and (e[1] in axis2.nodes): # edges from axis1 to axis2
h.connect(
axis1,
e[0],
15,
axis2,
e[1],
-15,
stroke_width="0.34",
stroke_opacity="0.4",
stroke="magenta",
)

h.save()
2 changes: 2 additions & 0 deletions examples/modern_example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
Loading