Visualizing points using Graphics.EasyPlot
Sometimes, it's convenient to simply visualize data points before clustering or classifying to inspect the data. This recipe will feed a list of points to a plotting library to easily see a diagram of the data.
Getting ready
Install easyplot from cabal:
$ cabal install easyplot
Create a CSV file containing two-dimensional points:
$ cat input.csv 1,2 2,3 3,1 4,5 5,3 6,1
How to do it…
In a new file, Main.hs
, follow these steps:
- Import the required library to read in CSV data as well the library to plot points:
import Text.CSV import Graphics.EasyPlot
- Create a helper function to convert a list of string records into a list of doubles. For example, we want to convert
[ "1.0,2.0", "3.5,4.5" ]
into[ (1.0, 2.0), (3.5, 4.5) ]
:tupes :: [[String]] -> [(Double, Double)] tupes records = [ (read x, read y) | [x, y] <- records ]
- In
main
, parse the CSV file to be used later on:main = do result <- parseCSVFromFile "input...