我正在探索racket
中的繪圖工具,我不得不說,迄今爲止我對它印象非常深刻。但是,我遇到了一個小小的困難。單色球拍中的散點圖
我試圖做一個散點圖,其中每個點都有自己的顏色(用於可視化分類算法)。但是,我不知道如何讓每個點都有自己的顏色。可能嗎?
這裏是我到目前爲止已經試過:
(define (random-choice l)
(list-ref l (random (length l))))
(define (scatter data)
(let ([x-max (apply max (map first data))]
[x-min (apply min (map first data))]
[y-max (apply max (map second data))]
[y-min (apply min (map second data))]
[colors (build-list 20
; here I am trying to create a list of desired colors
; ,but an error tells me that only single elements are accepted
(λ _ (random-choice (list "red" "blue")))])
(parameterize ([plot-new-window? #t]
[point-sym 'dot]
[point-size 20])
(plot (points data
#:color colors)
#:x-max x-max
#:x-min x-min
#:y-max y-max
#:y-min y-min))))
大致相當於在R
是:
c <- data.frame(x=rnorm(10),y=rnorm(10))
colors <- sample(c("red","blue"),10,replace=TRUE)
plot(c$y,c$x,col=colors)
順便說一句,我會歡迎任何(所有)評論我的代碼,例如簡化繪圖的邊界規範。