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 to do it...

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 to worry about messy data simplifies a lot of things!

See also

  • Adding lines to scatter charts.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.19.243