2014-03-24 133 views
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图。我不确定的部分是如何从索引结构(例如矢量)转到图上的一个点。另外,我不确定如何绘制连接聚集点的线。上面的示例应该在第一个群集中的三个点中有一行(最好是平滑的),并且由于群集中只有一个点,因此不会穿过最后一个群集。

回答

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-hermiteinterpolation使线顺利,并且我正在使用add-points function将数据点添加到plot

你会发现more interpolation examples here

但三点是不够的,良好的插值,所以你应该考虑使用线性插值来代替:

(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))) 

linear interpolation

更新:

让我们仔细看看我在这里做。

首先,我用解构提取数据点和聚类坐标(我假设你总是有下列数据点的单一集群):

(defn my-plot [[data [[cx cy]]]] 

然后我打破嵌套向量的[x y]双成两个向量(每个尺寸):

(let [x (map first data) 
     y (map second data)] 

然后我创建一个剧情对象和使用数据点绘制一条线就可以了:

(-> (xy-plot x y) 

然后,我将原始数据点(蓝点):

 (add-points x y) 

和群集(绿点):

 (add-points [cx] [cy]) 

最后,我显示导致情节:

 view))) 

在我的第一个例子中,我也使用插值使线更平滑:

 lbound (apply min x) 
     rbound (apply max x) 
     interp (interpolate data :cubic-hermite)] 
    (-> (function-plot interp lbound rbound) 

我在这里使用function-plot,因为interp对象是函数。

+0

如果我想在没有插值的情况下进行绘制,需要从第一个函数中删除什么?我尝试从'function-plot'中删除'interp'和interp这行,但是我把太多的参数传给了函数(2)。 – sunspots

+0

看到我的第二个例子没有内插的情节。 –

+0

使用后者my-plot,我将如何修改它以在同一图表中绘制原始点和集群? @LeonidBeschastny – sunspots