1

考虑一个输出嵌套向量的函数,例如

[[[-0.6925523827697917 -0.4095089425269985]
  [-0.03856010899727634 0.8427233420960013]
  [-2.609986195686694E-13 -1.680032093051418E-12]]
 [[0.7203362514229046 -0.3494564274369062]]]

在单括号之间,即[-0.6925523827697917 -0.4095089425269985],是要在笛卡尔坐标中绘制的数字。

此外,另一个括号内还有向量,即

[[0.7203362514229046 -0.3494564274369062]]

这表示一个集群。

我正在寻求绘制点,即上面的向量,并绘制一条连接集群内点的线。因此,集群内的点将[[-0.6925523827697917 -0.4095089425269985] [-0.03856010899727634 0.8427233420960013] [-2.609986195686694E-13 -1.680032093051418E-12]]被连接起来。

我的第一个想法是使用 Incanter 的 xy 图。我不确定的部分是如何从诸如向量之类的索引结构到绘图上的一个点。此外,我不确定如何绘制连接聚集点的线。上面的示例应该有一条线(最好是平滑的)通过第一个集群中的三个点,并且没有一条线通过最后一个集群,因为集群中只有一个点。

4

1 回答 1

1

我不确定你想要什么,但据我所知,它是这样的:

(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 spline interpolation

我正在使用: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.

于 2014-03-25T09:42:58.330 回答