我不确定你想要什么,但据我所知,它是这样的:
(use '(incanter core charts interpolation))
(defn my-plot [[data [[cx cy]]]]
(let [x (map first data)
y (map second data)
lbound (apply min x)
rbound (apply max x)
interp (interpolate data :cubic-hermite)]
(-> (function-plot interp lbound rbound)
(add-points x y)
(add-points [cx] [cy])
view)))

我正在使用:cubic-hermite
样条插值使线条平滑,并且我正在使用add-points
函数将数据点添加到绘图中。
您会在此处找到更多插值示例。
But three points isn't enough for good interpolation, so you should consider using linear interpolation instead:
(defn my-plot [[data [[cx cy]]]]
(let [x (map first data)
y (map second data)]
(-> (xy-plot x y)
(add-points x y)
(add-points [cx] [cy])
view)))

Update:
Let's have a closer look at what I'm doing here.
First, I'm using destructuring to extract data points and cluster coordinates (I'm assuming that you always have a single cluster following your data points):
(defn my-plot [[data [[cx cy]]]]
Then I'm breaking nested vector of [x y]
pairs into two vectors (one for each dimension):
(let [x (map first data)
y (map second data)]
Then I'm creating a plot object and drawing a line on it using your data points:
(-> (xy-plot x y)
Then I'm adding original data point (blue dots):
(add-points x y)
and your cluster (green dot):
(add-points [cx] [cy])
Finally, I'm displaying resulting plot:
view)))
In my first example I'm also using interpolation to make the line smoother:
lbound (apply min x)
rbound (apply max x)
interp (interpolate data :cubic-hermite)]
(-> (function-plot interp lbound rbound)
I'm using function-plot
here because interp
object is a function.