Netgraph

Netgraph: Publication-quality Network Visualisations in Python - Published in JOSS (2023)

https://github.com/paulbrodersen/netgraph

Science Score: 95.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 9 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
    1 of 10 committers (10.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

graph graph-tool igraph matplotlib network network-analysis network-science networkx publication-quality-plots python visualization

Scientific Fields

Mathematics Computer Science - 84% confidence
Last synced: 6 months ago · JSON representation

Repository

Publication-quality network visualisations in python

Basic Info
  • Host: GitHub
  • Owner: paulbrodersen
  • License: gpl-3.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 23.8 MB
Statistics
  • Stars: 727
  • Watchers: 10
  • Forks: 43
  • Open Issues: 15
  • Releases: 2
Topics
graph graph-tool igraph matplotlib network network-analysis network-science networkx publication-quality-plots python visualization
Created over 9 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

Netgraph

Publication-quality Network Visualisations in Python

Downloads DOI DOI

Netgraph is a Python library that aims to complement existing network analysis libraries such as such as networkx, igraph, and graph-tool with publication-quality visualisations within the Python ecosystem. To facilitate a seamless integration, Netgraph supports a variety of input formats, including networkx, igraph, and graph-tool Graph objects. Netgraph implements numerous node layout algorithms and several edge routing routines. Uniquely among Python alternatives, it handles networks with multiple components gracefully (which otherwise break most node layout routines), and it post-processes the output of the node layout and edge routing algorithms with several heuristics to increase the interpretability of the visualisation (reduction of overlaps between nodes, edges, and labels; edge crossing minimisation and edge unbundling where applicable). The highly customisable plots are created using Matplotlib, and the resulting Matplotlib objects are exposed in an easily queryable format such that they can be further manipulated and/or animated using standard Matplotlib syntax. Finally, Netgraph also supports interactive changes: with the InteractiveGraph class, nodes and edges can be positioned using the mouse, and the EditableGraph class additionally supports insertion and deletion of nodes and edges as well as their (re-)labelling through standard text-entry.

Installation

Install the current release of netgraph from PyPI:

shell pip install netgraph

If you are using (Ana-)conda (or mamba), you can also obtain Netgraph from conda-forge:

shell conda install -c conda-forge netgraph

Documentation

Numerous tutorials, code examples, and a complete documentation of the API can be found on ReadTheDocs.

Quickstart

``` python import matplotlib.pyplot as plt from netgraph import Graph, InteractiveGraph, EditableGraph

Several graph formats are supported:

1) edge lists

graph_data = [(0, 1), (1, 2), (2, 0)]

2) edge list with weights

graph_data = [(0, 1, 0.2), (1, 2, -0.4), (2, 0, 0.7)]

3) full rank matrices

import numpy graph_data = np.random.rand(10, 10)

4) networkx Graph and DiGraph objects (MultiGraph objects are not supported, yet)

import networkx graphdata = networkx.karateclub_graph()

5) igraph.Graph objects

import igraph graph_data = igraph.Graph.Famous('Zachary')

6) graph_tool.Graph objects

import graphtool.collection graphdata = graph_tool.collection.data["karate"]

Create a non-interactive plot:

Graph(graph_data) plt.show()

Create an interactive plot, in which the nodes can be re-positioned with the mouse.

NOTE: you must retain a reference to the plot instance!

Otherwise, the plot instance will be garbage collected after the initial draw

and you won't be able to move the plot elements around.

For related reasons, if you are using PyCharm, you have to execute the code in

a console (Alt+Shift+E).

plotinstance = InteractiveGraph(graphdata) plt.show()

Create an editable plot, which is an interactive plot with the additions

that nodes and edges can be inserted or deleted, and labels and annotations

can be created, edited, or deleted as well.

plotinstance = EditableGraph(graphdata) plt.show()

Netgraph uses Matplotlib for creating the visualisation.

Node and edge artistis are derived from matplotlib.patches.PathPatch.

Node and edge labels are matplotlib.text.Text instances.

Standard matplotlib syntax applies.

fig, ax = plt.subplots(figsize=(5,4)) plotinstance = Graph([(0, 1)], nodelabels=True, edgelabels=True, ax=ax) plotinstance.nodeartists[0].setalpha(0.2) plotinstance.edgeartists[(0, 1)].setfacecolor('red') plotinstance.edgelabelartists[(0, 1)].setstyle('italic') plotinstance.nodelabelartists[1].setsize(10) ax.settitle("This is my fancy title.") ax.set_facecolor('honeydew') # change background color fig.canvas.draw() # force redraw to display changes fig.savefig('test.pdf', dpi=300) plt.show()

Read the documentation for a full list of available arguments:

help(Graph) help(InteractiveGraph) help(EditableGraph) ```

Examples

Example visualisations

Citing Netgraph

If you use Netgraph in a scientific publication, I would appreciate citations to the following paper:

Brodersen, P. J. N., (2023). Netgraph: Publication-quality Network Visualisations in Python. Journal of Open Source Software, 8(87), 5372, https://doi.org/10.21105/joss.05372

Bibtex entry:

bibtex @article{Brodersen2023, doi = {10.21105/joss.05372}, url = {https://doi.org/10.21105/joss.05372}, year = {2023}, publisher = {The Open Journal}, volume = {8}, number = {87}, pages = {5372}, author = {Paul J. N. Brodersen}, title = {Netgraph: Publication-quality Network Visualisations in Python}, journal = {Journal of Open Source Software}, }

Recent changes

  • 4.13.1 Improved initialization of k parameter in get_fruchterman_reingold_layout (issue #79).
  • 4.13.0 Wrote an article on Netgraph for the Journal of Open Source Software (latest draft in /publication).
  • 4.12.12 Expanded the documentation to cover installation of optional dependencies, automated testing, and troubleshooting issues with Matplotlib event handling (issue #69).
  • 4.12.11 Mitigated a bug in EditableGraph that occurred when deleting a node while hovering over an edge incident to that node (issue #66).
  • 4.12.10 Fixed a bug with automatic node label rescaling if the node label fontsize was specified using the fontsize keyword argument (instead of just size).
  • 4.12.9 Fixed a bug that occurred when the distance argument to _shorten_line_by was equal or smaller than zero.
  • 4.12.8 Fixed a bug that occurred with recent numpy versions when using multi-partite or shell layouts with un-equal numbers of nodes in each layer (issue #65).
  • 4.12.7 Fixed a bug that occurred with recent Matplotlib versions when using the rectangle selector in InteractiveGraph.
  • 4.12.6 Added support for graphs with nodes but no edges to EditableGraph (issue #62).
  • 4.12.5 Added support for empty graphs in EditableGraph (issue #62).
  • 4.12.4 Turned off clipping of self-loop paths.
  • 4.12.3 Bugfix: stopped overwriting step parameter in get_community_layout.
  • 4.12.2 Improved node positions rescaling for some layouts & standardised node position padding across all layouts.
  • 4.12.1 Fixed a bug/deprecation issue that occurred with new versions of Matplotlib if an axis was provided (thanks @speedsmith!).
  • 4.12.0 Implemented the geometric node layout, which infers node positions from given edge lengths.
  • 4.11.8 Plotting of graphs with a single node is now actually supported. Thanks @Alexander-Wilms.
  • 4.11.7 Removed instances of (deprecated) np.float / np.int types (issue #58).
  • 4.11.6 Added documentation on hyperlinks (issue #56).
  • 4.11.5 Resolved a SyntaxWarning.
  • 4.11.4 Fixed a bug that occurred when using edge annotations.
  • 4.11.3 Cleaned build directory and removed several outdated files.
  • 4.11.2 Fixed a bug that prevented changing the axis background colour.
  • 4.11.1 Resolved warnings during build process.
  • 4.11.0 Switched from setup.py based installation to pyproject.toml/wheels.
  • 4.10.4 Added support for custom graph classes that inherit from networkx/igraph/graph-tool base Graph classes (issue #53).
  • 4.10.3 Improved the error message for incomplete iterable arguments (issue #55).
  • 4.10.2 Fixed issue #48 (again, sorry).
  • 4.10.1 Implemented flag that controls bundling of parallel edges in the curved edge layout (bundle_parallel_edges).
  • 4.10.0 Implemented grid-mode for the InteractiveGraph class to facilitate alignment of nodes (toggle with 'g').
  • 4.9.7 Fixed a bug introduced in version 4.9.5 in the computation of repulsive forces in the spring layout (i.e. the default layout).
  • 4.9.6 Fixed issue #51, which occurred in the community node layout if a node had no connections to other nodes in its community.
  • 4.9.5 Improved the routine that reduces node overlaps in the spring and community node layouts.
  • 4.9.4 Fixed a bug that occurred in getcurvededges if the k parameter was not set explicitly.
  • 4.9.3 Improved placement of nodes in instances where all nodes are aligned within any one dimension.
  • 4.9.2 Fixed an issue that occurred when using the dot node layout for a graphs with multiple components.
  • 4.9.1 Fixed issue #48, which occurred when computing a curved edge layout for graphs with multiple components. Also improved edge routing slightly.
  • 4.9.0 Implemented a layered and a shell layout for multi-partite graphs.
  • 4.8.2 Fixed issue #45, which prevented a warning to be raised when trying to plot networkx.MultiGraph instances.
  • 4.8.1 Fixed issue #44, that occurred if a single node was plotted with the Sugiyama layout (thanks @wilkeber).
  • 4.8.0 Refined community node layout. Communities are rotated w.r.t. each other to reduce the length of edges between them.
  • 4.7.1 Fixed issue #41, which occurred when computing the community layout for communities without within-community edges.
  • 4.7.0 Implemented a radial tree node layout.
  • 4.6.0 Support drawing of graph_tool.Graph objects.
  • 4.5.0 Support custom mappings for mouse-over highlight events (issue #39).
  • 4.4.1 Corrected imports for testing _arcdiagram.py.
  • 4.4.0 Added bipartite node layouts.
  • 4.3.0 Added the ArcDiagram class and interactive/editable variants.
  • 4.2.4 Plotting of graphs with a single node is now supported.
  • 4.2.3 Fixed a bug that occurred when using the community layout with at least one community containing a single node.
  • 4.2.2 Fixed a bug that occurred every time an InteractiveGraph was initialised without tabular annotations.
  • 4.2.1 Added online documentation.

Help, I don't know how to do ...!

Please raise an issue. Include any relevant code and data in a minimal, reproducible example. If applicable, make a sketch of the desired result with pen and paper, take a picture, and append it to the issue.

Bug reports are, of course, always welcome. Please make sure to include the full error trace.

If you submit a pull request that fixes a bug or implements a cool feature, I will probably worship the ground you walk on for the rest of the week. Probably.

Finally, if you do email me, please be very patient. I rarely check the email account linked to my open source code, so I probably will not see your emails for several weeks, potentially longer. Also, I have a job that I love and that pays my bills, and thus takes priority. That being said, the blue little notification dot on GitHub is surprisingly effective at getting my attention. So please just raise an issue.

Owner

  • Name: Paul Brodersen
  • Login: paulbrodersen
  • Kind: user
  • Location: Oxford, UK
  • Company: University of Oxford

Computational neuroscientist/applied mathematician/software developer working on biologically plausible variants of artificial neural networks.

JOSS Publication

Netgraph: Publication-quality Network Visualisations in Python
Published
July 19, 2023
Volume 8, Issue 87, Page 5372
Authors
Paul J. n. Brodersen ORCID
Department of Pharmacology, University of Oxford, United Kingdom
Editor
Rachel Kurchin ORCID
Tags
graph network visualisation visualization matplotlib networkx igraph graph-tool

GitHub Events

Total
  • Issues event: 4
  • Watch event: 53
  • Issue comment event: 6
  • Push event: 3
  • Pull request event: 2
  • Fork event: 2
Last Year
  • Issues event: 4
  • Watch event: 53
  • Issue comment event: 6
  • Push event: 3
  • Pull request event: 2
  • Fork event: 2

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 747
  • Total Committers: 10
  • Avg Commits per committer: 74.7
  • Development Distribution Score (DDS): 0.017
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Paul Brodersen p****n@g****m 734
chenghuzi t****s@i****m 2
Vladimir Fokow 5****w 2
Daniel S. Katz d****z@i****g 2
Allan L. R. Hansen a****h@g****m 2
speedsmith 5****h 1
adleris 5****s 1
Rodrigo Morais 5****u 1
Hamed Mohammadpour h****2@g****m 1
Pablo P****r@i****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 89
  • Total pull requests: 13
  • Average time to close issues: 2 months
  • Average time to close pull requests: 4 days
  • Total issue authors: 61
  • Total pull request authors: 12
  • Average comments per issue: 4.99
  • Average comments per pull request: 1.46
  • Merged pull requests: 10
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 2
  • Average time to close issues: 2 days
  • Average time to close pull requests: 11 days
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 3.33
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • lcastri (5)
  • fishbacp (4)
  • fsoupimenta (4)
  • a-arbabian (4)
  • jamesbraza (3)
  • rjalexa (3)
  • Franck-Delaplace (3)
  • kkdd (2)
  • HamedMP (2)
  • ghost (2)
  • white-gecko (2)
  • AllanLRH (2)
  • ortega2247 (2)
  • ste-lau (2)
  • LBeghini (2)
Pull Request Authors
  • siantonelli (3)
  • rodigu (2)
  • chenghuzi (1)
  • clara-moy (1)
  • adleris (1)
  • HamedMP (1)
  • wilkeber (1)
  • speedsmith (1)
  • cclauss (1)
  • AllanLRH (1)
  • VladimirFokow (1)
Top Labels
Issue Labels
enhancement (11) bug (7) help wanted (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 4,249 last-month
  • Total dependent packages: 8
  • Total dependent repositories: 15
  • Total versions: 53
  • Total maintainers: 1
pypi.org: netgraph

Python drawing utilities for publication quality plots of networks.

  • Versions: 53
  • Dependent Packages: 8
  • Dependent Repositories: 15
  • Downloads: 4,249 Last month
Rankings
Dependent packages count: 1.6%
Stargazers count: 2.6%
Average: 3.8%
Dependent repos count: 3.8%
Downloads: 4.2%
Forks count: 6.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • Pillow *
  • networkx *
  • numpydoc *
  • sphinx *
  • sphinx-gallery *
  • sphinx-rtd-theme *
optional-requirements.txt pypi
  • pytest *
  • pytest-mpl *
requirements.txt pypi
  • grandalf *
  • matplotlib >=1.5
  • numpy *
  • rectangle-packer *
  • scipy *
setup.py pypi
  • grandalf *
  • matplotlib *
  • numpy *
  • rectangle-packer *
  • scipy *
.github/workflows/draft-pdf.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v1 composite
  • openjournals/openjournals-draft-action master composite
pyproject.toml pypi
  • grandalf *
  • matplotlib >= 1.5
  • numpy *
  • rectangle-packer *
  • scipy *