Hive Plots in using Python & matplotlib!
Jupyter Notebook Python Shell
Latest commit 4831a31 Jan 17, 2017 @ericmjl committed on GitHub Merge pull request #16 from ericmjl/pyup-update-matplotlib-1.5.3-to-2…
….0.0

Update matplotlib to 2.0.0
Permalink
Failed to load latest commit information.
examples/protein_graphs bug fix and code cleanup in hiveplot.py, re-ran tests, all passed May 9, 2016
hiveplot
tests
.binstar.yml
.gitignore
.travis.yml
LICENSE
MANIFEST.in
README.md
appveyor.yml added appveyor config Jul 15, 2016
build.sh
codecov.yml create codecov.yml Jul 15, 2016
environment.yml
requirements.txt
setup.cfg
setup.py
test.sh

README.md

hiveplot

Hive Plots in using Python & matplotlib!

pypi page: https://pypi.python.org/pypi/hiveplot

Badges

  • Code Issues (QuantifiedCode)
  • Build Status (Travis CI)

How to install hiveplot

To install hiveplot, you need to have matplotlib installed - that's the only dependency required. If you are using networkx to create your graphs, you will need that as well.

To run one of the notebook examples, you may need to install the Protein Interaction Network package from GitHub.

How to use hiveplot

Hive Plots are used for visualizing large network data in a rational way. Hive Plots are non-trivial to create, but I have made this Python package to help boil it down to the essentials.

The original creator of Hive Plots is Martin Krzywinski of the BCGSC. His website is at: http://mkweb.bcgsc.ca

An example graph is available in the test folder. Alternatively, you can view the IPython notebook online: http://nbviewer.ipython.org/github/ericmjl/hiveplot/blob/master/test/Tests.ipynb

To start, I assume that you have some network data. In your network data, you will have nodes and edges.

Firstly, decide how you will group your nodes. Hive plots work best with up to 3 groups. Secondly, decide how you will order your nodes along each group. A common ordering is by degree centrality, which is how hiveplot currently does it automatically. Together, you can put together the first parameter put into hiveplot, which is a dictionary of {group:[list_of_nodes]}.

Example code:

## assume that you have a graph called G
nodes = dict()
nodes['group1'] = [(n,d) for n, d in G.nodes(data=True) if d == some_criteria()]
nodes['group2'] = [(n,d) for n, d in G.nodes(data=True) if d == other_criteria()]
nodes['group3'] = [(n,d) for n, d in G.nodes(data=True) if d == third_criteria()]

You may wish to sort your nodes by some criteria.

for group, nodelist in nodes.items():
    nodes[group] = sorted(nodelist, key=keyfunc())
    ...

Note: keyfunc() might work on the node attributes d. That is why we included the d dictionary of attributes inside.

Finally, you will need to get just the node ids out.

    nodes[group] = [n for n, d in nodes[group]]

Next, you will need to group your edges. Do this in a similar fashion as nodes.

edges = dict()
edges['group1'] = [(u,v,d) for u,v,d in G.edges(data=True) if d == some_criteria()]
...

Finally, you will need a color map for the nodes and edges respectively.

nodes_cmap = dict()
nodes_cmap['group1'] = 'green'
nodes_cmap['group2'] = 'red'
nodes_cmap['group3'] = 'blue'

edges_cmap = dict()
edges_cmap['group1'] = 'green'
...

Once all of this is setup, you can plot the Hive Plot!

h = HivePlot(nodes, edges, nodes_camp, edges_cmap)
h.draw()

All contributions to improve the package are welcome!

Change Log

0.1.8.2:

  1. Changed the setup script to use MANIFEST.in.

0.1.7.4:

  1. Fixed a bug that would cause drawing to not work on Python 3 dict_key objects do not have a .index(item) the way lists have.

0.1.7.1:

  1. Changed all tabs into four spaces.