Book Image

Clojure Data Analysis Cookbook - Second Edition

By : Eric Richard Rochester
Book Image

Clojure Data Analysis Cookbook - Second Edition

By: Eric Richard Rochester

Overview of this book

Table of Contents (19 chapters)
Clojure Data Analysis Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating function plots with Incanter


Sometimes we don't want to graph data, but plot the values of a function over a given domain instead. In this recipe, we'll see how to graph an inverse log function, although any other function would work just as well.

Getting ready

We'll use the same dependencies in our project.clj file as we did in Creating scatter plots with Incanter.

We'll use this set of imports in our script or REPL:

(require '[incanter.core :as i]
         '[incanter.charts :as c])

How to do it...

We just create and display a function-plot object:

(def f-plot
  (c/function-plot
    #(/ 1.0 (Math/log %)) 0.0 0.99
    :title "Inverse log function."
    :y-label "Inverse log"))
 i/view f-plot)

The graph is, as we would expect, like this:

How it works...

The incanter.charts/function-plot function takes the function to plot and the range of the domain (from 0.0 to 1.0 in this case). We've added some labels to make things clearer, but overall, this is a very straightforward function. Not having...