Is that possible to plot a simple graph using Haskell ? Can any of you show me how to do that ?
The graph should contain at lest 3 points
Apart from Chart, there are some very good language-agnostic plotting libraries/systems, usable from Haskell. I use Vega and matplotlib myself.
You can use Vega-Lite with the Haskell package hvega, which gives you an html file with a chart drawn with the vega-lite js library.
Basic usage:
import Graphics.Vega.VegaLite
main = do
toHtmlFile "myplot.html" $ toVegaLite
[ dataFromUrl "rows.tsv" [TSV]
, mark Bar [MTooltip TTEncoding]
, enc []
, height 600
, width 400
]
where enc = encoding
. position X [ PName "date"
, PmType Ordinal
]
. position Y [ PName "joy"
, PmType Quantitative
]
. color [MName "activity", MmType Nominal]
(Then put the tsv and html files in a directory served by a web server, e.g. $ python -m SimpleHTTPServer in that directory.) This example gives a stacked bar chart of three columns (assuming rows.tsv has the column names used in the code):
The documentation has lots of examples: https://hackage.haskell.org/package/hvega/docs/Graphics-Vega-Tutorials-VegaLite.html
If you can live with installing some Python deps, matplotlib makes it easy to interactively plot and explore.
Simple example:
onscreen $ let b = bar [21..23] in
b [56,57,56] @@ [o2 "color" "#4C78A8"]
% b [26,24,25] @@ [o2 "color" "#F58518"]
% b [16,15,14] @@ [o2 "color" "#E45756"]
See the readme for more examples.
The dataframe library is a tool for exploratory data analysis in Haskell, and lets you plot ASCII graphs in the REPL:
as well as saving it to interactive browser charts like
ghci> P.plotScatter "dogs" "joy" df >>= P.showInDefaultBrowser
Saving plot to: ~/plot-chart_ACzzzidiLidnydNLE32ZmgMH114vwdH87VQwxANWcezbIZ.html
You can also use it as a Jupyter notebook, this is from a demo you can try:
Plotly (originally for R) is usable from Haskell with the package plotlyhs. You get out a standalone html page with an interactive plot.
Example usage: https://glutamate.github.io/plotlyhs/
There are various packages that create gnuplot scripts which can be used to make png's etc: https://hackage.haskell.org/packages/search?terms=gnuplot
haskell-chart seems to be good.
The wiki contains a list of graphs drawn using that package.