Database Reference
In-Depth Information
Saving Incanter graphs to PNG
So far, we've been viewing the graphs we've created in a window on our computer. This is
extremely handy, especially to quickly generate a graph and see what's in it. However, the
chart would be more useful if we could save it. Then we could embed it in Word documents
or web pages or print it so that we can hang it on the wall.
In this recipe, we'll save a graph of the iris data that we created in
Creating scatter plots
with Incanter
.
Getting ready
We'll use the same dependencies in our
project.clj
ile as we did in
Creating scatter plots
with Incanter
, and this set of imports in our script or REPL:
(require '[incanter.core :as i]
'[incanter.charts :as c])
We'll also use the chart object that we created in
Creating scatter plots with Incanter
, and
we'll keep using the
iris-petal-scatter
variable name for it.
How to do it...
Since we already have the chart, saving it is simple. We just call
incanter.core/save
on it
with the ilename we want to save it to:
(i/save iris-petal-scatter "iris-petal-scatter.png")
How it works...
Calling
incanter.core/save
on a chart saves it as a PNG ile. We can also include
options to the
save
function to set the output image's dimensions using the
:height
and
:width
parameters.
There's also another way to save images. If we right-click on a chart after displaying it with
incanter.core/view
, it gives us the option to save the chart from there.