Displaying a line graph using gnuplot
An Internet connection is typically unnecessary for plotting a graph. So, in this recipe, we will demonstrate how to make a line graph locally.
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 on its main website available at http://www.gnuplot.info.
After gnuplot is set up, install the EasyPlot
Haskell library using cabal as follows:
$ cabal install easyplot
How to do it…
- Import the
EasyPlot
library as follows:import Graphics.EasyPlot
- Define a list of numbers to plot as follows:
main = do let values = [4,5,16,15,14,13,13,17]
- Plot the chart on the
X11
window as shown in the following code snippet. TheX11
X Window System terminal is used by many Linux-based machines. If running on Windows, we should instead use theWindows
terminal...