Skip to content

Repository files navigation

Planarity

The planarity repository provides the source code for the planarity Python package. The planarity package was originally developed to provide Python and NetworkX developers with a Python API to access planar graph testing, embedding, drawing, and forbidden subgraph isolation algorithms from the Edge Addition Planarity Suite (EAPS).

The planarity repository has now been transferred to the Github Graph Algorithms Organization. The planarity repository and Python package have been updated with the full set of planarity-related algorithms from EAPS as well as all public methods from its generalized graph library to enable development of a wide range of high-performance graph algorithms and applications.

Example

In [1]: # Example of the complete graph of 5 nodes, K5, which is not planar.

In [2]: import planarity

In [3]: edgelist = [('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'),
   ...:             ('b', 'c'),('b', 'd'),('b', 'e'),
   ...:             ('c', 'd'), ('c', 'e'),
   ...:             ('d', 'e')]

In [4]: print(planarity.is_planar(edgelist))
False

In [5]: # Remove an edge to make the graph planar

In [6]: edgelist.remove(('a','b'))

In [7]: print(planarity.is_planar(edgelist))
True

In [8]: # Make an ascii text drawing

In [9]: # Create single instance of PGraph from edgelist upon which to operate

In [10]: P = planarity.PGraph(edgelist)

In [11]: # Produce mapping of nodes to their original labels

In [12]: print(P.mapping())
{1: 'e', 2: 'b', 3: 'd', 4: 'a', 5: 'c'}

In [13]: # Make text drawing

In [14]: print(P.ascii())
----1----
| | |   |
| | -3--|
| |  ||||
| -2--|||
|  |  |||
---5---||
 |     ||
 ---4----

Note that edge (a, b) would correspond to labels (4, 2), which is not present in the drawing of this planar graph.

See here for more examples.

For further details on development setup and installation, please see this wiki page on the planarity repository.

License

Planarity (the 'planarity' Python package; the software) is released under this BSD-3-Clause license.

    Copyright (c) 2016-2026, Planarity Developers
    John M. Boyer john.boyer.phd@gmail.com
    Wanda B. K. Boyer wbkboyer@gmail.com
    Aric Hagberg aric.hagberg@gmail.com
    All rights reserved.

    Planarity includes the Edge Addition Planarity Suite, which is
    Copyright (c) 1997-2026, John M. Boyer.
    The BSD-3-Clause license for the Edge Additional Planarity Suite
    included in Planarity appears here.

About

Planar graph algorithms

Resources

Stars

44 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages