diff --git a/examples.md b/examples.md index 4c4d45a..4629893 100644 --- a/examples.md +++ b/examples.md @@ -89,6 +89,14 @@ for plotting or rendering graphics. - [Generating videos with literate Futhark](examples/literate-video.html) - [Reading and writing files in literate Futhark](examples/literate-files.html) +# Plotting + +Literate Futhark allows direct use of +[gnuplot](http://www.gnuplot.info/). These examples show simple and +common cases. + +- [Plotting a histogram](examples/plot-histogram.html) + # Examples from Dex The following examples are ported from diff --git a/examples/plot-histogram-img/f119313ba60a76bac264ae2e9fa48901-plot.png b/examples/plot-histogram-img/f119313ba60a76bac264ae2e9fa48901-plot.png new file mode 100644 index 0000000..5cc5448 Binary files /dev/null and b/examples/plot-histogram-img/f119313ba60a76bac264ae2e9fa48901-plot.png differ diff --git a/examples/plot-histogram.fut b/examples/plot-histogram.fut new file mode 100644 index 0000000..c6316ff --- /dev/null +++ b/examples/plot-histogram.fut @@ -0,0 +1,22 @@ +-- # Plotting a histogram + +-- This can be done by computing a histogram in Futhark and then using +-- a box plot. Here we produce some arbitrary values, discretised aong +-- *k* bins. + +def plot k n : ([]i64,[]i32) = + let vs = iota n |> map (f64.i64 >-> f64.cos >-> (+1) >-> (*(f64.i64 k/2)) >-> i64.f64) + in (iota k, + hist (+) 0 k vs (replicate n 1)) + +-- > :gnuplot {data=plot 100 10000}; +-- set xrange [0:100]; +-- set style fill solid 1.0 +-- plot data with boxes + + +-- ## See also +-- +-- [Gnuplots built-in support for histograms](http://gnuplot.info/docs_6.1/loc5256.html). +-- +-- [Generalised histograms.](histogram.html).