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

Displaying a scatter plot of two-dimensional points


This recipe covers a quick and easy way to visualize a list of 2D points as scattered dots within an image.

Getting ready

The library used in this recipe uses gnuplot to render the graph. We should first install gnuplot.

On Debian-based systems such as Ubuntu, we can install it using apt-get as follows:

$ sudo apt-get install gnuplot-x11

The official place to download gnuplot is from its main website, http://www.gnuplot.info.

After gnuplot is set up, install the easyplot Haskell library using cabal as follows:

$ cabal install easyplot

Also, install a helper CSV package as follows:

$ cabal install csv

Also, create two comma-separated files, input1.csv and input2.csv, which represent two separate sets of points as follows:

$ cat input1.csv
1,2
3,2
2,3
2,2
3,1
2,2
2,1
$ cat input2.csv
7,4
8,4
6,4
7,5
7,3
6,4
7,6

How to do it…

  1. Import the relevant packages as follows:

    import Graphics.EasyPlot
    
    import Text.CSV
  2. Define a helper function to convert a...