Search code examples
clojureincanter

How can you set the color of Incanter's add-lines?


When calling the add-lines function from the Clojure library Incanter, the added lines will use every color in the rainbow. However, I want every added line to be black. Figuring out how to do this has proven remarkably tricky. Can somebody help?


Solution

  • AFAICT you have to explicitly set display options for each add-lines call because they internally create separate datasets.

    (doto (xy-plot [1 2 3 4] [10 20 5 35])
      (add-lines [1 2 3 4] [20 5 30 15])
      (add-lines [1 2 3 4] [5 30 -1 20])
      ;; set color for each line dataset
      (set-stroke-color java.awt.Color/black :dataset 0)
      (set-stroke-color java.awt.Color/black :dataset 1)
      (set-stroke-color java.awt.Color/black :dataset 2)
      (view))
    

    Relevant GitHub issue here.