Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Visualizing a graph network


Graphical networks of edges and nodes can be difficult to debug or comprehend, and thus, visualization helps tremendously. In this recipe, we will convert a graph data structure into an image of nodes and edges.

Getting ready

To use Graphviz, the graph visualization library, we must first install it on the machine. The official website of Graphviz contains the download and installation instructions (http://www.graphviz.org). On Debian-based operating systems, Graphviz can be installed using apt-get as follows:

$ sudo apt-get install graphviz-dev graphviz

Next, we need to install the Graphviz Haskell bindings from Cabal as follows:

$ cabal install graphviz

How to do it…

  1. Import the relevant libraries as follows:

    import Data.Text.Lazy (Text, empty, unpack)
    import Data.Graph.Inductive (Gr, mkGraph)
    import Data.GraphViz (GraphvizParams, nonClusteredParams, graphToDot)
    import Data.GraphViz.Printing (toDot, renderDot)
  2. Create a graph defined by identifying the pairs of nodes...