Skip to content

Instantly share code, notes, and snippets.

@jolby
Created April 22, 2010 15:01
Show Gist options
  • Save jolby/375340 to your computer and use it in GitHub Desktop.
Save jolby/375340 to your computer and use it in GitHub Desktop.
Using com.evocomputing.colors with incanter to get semantic colors
(ns colorstats.core
(:use
(com.evocomputing [colors :only [create-color awt-color]])
(incanter [charts :only [line-chart set-stroke set-stroke-color bar-chart]]
[core :only [view]]
[datasets :only [get-dataset]])
(clojure.contrib [seq-utils :only [indexed]]))
(:require
[com.evocomputing.colors.palettes.core :as core-palettes]
[com.evocomputing.colors.palettes.color-brewer :as color-brewer]))
(defn line-chart-colors-example []
(doto (line-chart [:a :b :c :d] [10 20 5 35])
(set-stroke :width 4 :dash 5)
(set-stroke-color (awt-color (create-color :blue)))
view))
(defn bar-chart-rainbow-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (core-palettes/rainbow-hsl 12))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defn bar-chart-sequential-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (core-palettes/sequential-hsl 12))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defn bar-chart-diverge-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (core-palettes/diverge-hsl 12))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defn bar-chart-heat-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (core-palettes/heat-hsl 12))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defn bar-chart-terrain-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (core-palettes/terrain-hsl 12))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defn bar-chart-color-brewer-oranges-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (color-brewer/get-color-brewer-palette "Oranges" 9))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defn bar-chart-color-brewer-piyg-example []
(let [data (get-dataset :airline-passengers)
bchart (bar-chart :year :passengers :group-by :month :legend true :data data)
bchart-renderer (-> bchart .getPlot .getRenderer)
colors (map #'awt-color (color-brewer/get-color-brewer-palette "PiYG" 11))]
(doseq [[idx color] (indexed colors)]
(.setSeriesPaint bchart-renderer idx color))
(view bchart)))
(defproject colorstats "1.0.0-SNAPSHOT"
:description "Testing com.evocomputing.colors with incanter"
:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib "1.2.0-master-SNAPSHOT"]
[incanter "1.2.3-SNAPSHOT"]
[com.evocomputing/colors "1.0.0-SNAPSHOT"]]
:dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]
[leiningen/lein-swank "1.1.0"]
[jline "0.9.94"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment