当我在一组点上切换x和y坐标时,我得到以下奇怪的错误
File "min_working_example.py", line 8, in <module>
triang = tria.Triangulation(coords[:,1],coords[:,0])
File "/usr/lib/pymodules/python2.7/matplotlib/tri/triangulation.py", line 72, in __init__
dt = delaunay.Triangulation(self.x, self.y)
File "/usr/lib/pymodules/python2.7/matplotlib/delaunay/triangulate.py", line 123, in __init__
self.hull = self._compute_convex_hull()
File "/usr/lib/pymodules/python2.7/matplotlib/delaunay/triangulate.py", line 158, in _compute_convex_hull
hull.append(edges.pop(hull[-1]))
KeyError: 0
我在这里附加了一组点,以及可以生成此错误的最小工作示例。这是在ubuntu 13.10上的matplotlib 1.3与存储库中的版本。奇怪的是,只有这个数据集似乎有问题。
谢谢, Subramanya
代码:
from pylab import *
import matplotlib.tri as tria
coords = loadtxt("data.txt")
fig = figure()
ax = fig.add_subplot(111)
triang = tria.Triangulation(coords[:,0],coords[:,1])
ax.triplot(triang)
savefig('a.png')
triang2 = tria.Triangulation(coords[:,1],coords[:,0])
数据
-6.500000000000004663e-01 -8.660254037844383745e-01
-6.500000000000003553e-01 -6.062177826491067512e-01
-6.500000000000003553e-01 -3.464101615137751833e-01
-6.500000000000002442e-01 -8.660254037844355990e-02
-6.500000000000001332e-01 1.732050807568880635e-01
-6.500000000000000222e-01 4.330127018922196869e-01
-6.499999999999999112e-01 6.928203230275513658e-01
-6.499999999999998002e-01 9.526279441628826561e-01
-4.250000000000004885e-01 -9.959292143521041307e-01
-4.250000000000003220e-01 -7.361215932167725073e-01
-4.250000000000002665e-01 -4.763139720814408840e-01
-4.250000000000001554e-01 -2.165063509461093161e-01
-4.250000000000000444e-01 4.330127018922230731e-02
-4.249999999999999334e-01 3.031088913245539307e-01
-4.249999999999998224e-01 5.629165124598856096e-01
-4.249999999999997669e-01 8.227241335952174550e-01
-2.000000000000003442e-01 -8.660254037844382635e-01
-2.000000000000002331e-01 -6.062177826491067512e-01
-2.000000000000001499e-01 -3.464101615137751278e-01
-2.000000000000000389e-01 -8.660254037844355990e-02
-1.999999999999999556e-01 1.732050807568881190e-01
-1.999999999999998446e-01 4.330127018922196869e-01
-1.999999999999997613e-01 6.928203230275513658e-01
2.499999999999980016e-02 -7.361215932167725073e-01
2.499999999999985567e-02 -4.763139720814409950e-01
2.499999999999999445e-02 -2.165063509461093716e-01
2.500000000000007772e-02 4.330127018922225179e-02
2.500000000000017486e-02 3.031088913245538752e-01
2.500000000000029976e-02 5.629165124598854986e-01
2.499999999999998335e-01 -6.062177826491067512e-01
2.499999999999999722e-01 -3.464101615137752388e-01
2.500000000000001110e-01 -8.660254037844355990e-02
2.500000000000002220e-01 1.732050807568880080e-01
2.500000000000002776e-01 4.330127018922196314e-01
4.749999999999999778e-01 -4.763139720814410505e-01
4.750000000000000888e-01 -2.165063509461093993e-01
4.750000000000001998e-01 4.330127018922216853e-02
4.750000000000003109e-01 3.031088913245537642e-01
7.000000000000000666e-01 -3.464101615137752388e-01
7.000000000000001776e-01 -8.660254037844367092e-02
7.000000000000002887e-01 1.732050807568879525e-01
9.250000000000002665e-01 -2.165063509461093716e-01
9.250000000000004885e-01 4.330127018922221710e-02
1.150000000000000355e+00 -8.660254037844382358e-02
-6.500000000000003553e-01 -6.062177826491067512e-01
-6.500000000000003553e-01 -3.464101615137751833e-01
-6.500000000000002442e-01 -8.660254037844355990e-02
-6.500000000000001332e-01 1.732050807568880635e-01
-6.500000000000000222e-01 4.330127018922196869e-01
-6.499999999999999112e-01 6.928203230275513658e-01
-6.499999999999998002e-01 9.526279441628826561e-01
-4.250000000000004885e-01 -9.959292143521041307e-01
-4.250000000000003220e-01 -7.361215932167725073e-01
-4.250000000000002665e-01 -4.763139720814408840e-01
-4.250000000000001554e-01 -2.165063509461093161e-01
-4.250000000000000444e-01 4.330127018922230731e-02
-4.249999999999999334e-01 3.031088913245539307e-01
-4.249999999999998224e-01 5.629165124598856096e-01
-4.249999999999997669e-01 8.227241335952174550e-01
-2.000000000000003442e-01 -8.660254037844382635e-01
-2.000000000000002331e-01 -6.062177826491067512e-01
-2.000000000000001499e-01 -3.464101615137751278e-01
-2.000000000000000389e-01 -8.660254037844355990e-02
-1.999999999999999556e-01 1.732050807568881190e-01
-1.999999999999998446e-01 4.330127018922196869e-01
-1.999999999999997613e-01 6.928203230275513658e-01
2.499999999999980016e-02 -7.361215932167725073e-01
2.499999999999985567e-02 -4.763139720814409950e-01
2.499999999999999445e-02 -2.165063509461093716e-01
2.500000000000007772e-02 4.330127018922225179e-02
2.500000000000017486e-02 3.031088913245538752e-01
2.500000000000029976e-02 5.629165124598854986e-01
2.499999999999998335e-01 -6.062177826491067512e-01
2.499999999999999722e-01 -3.464101615137752388e-01
2.500000000000001110e-01 -8.660254037844355990e-02
2.500000000000002220e-01 1.732050807568880080e-01
2.500000000000002776e-01 4.330127018922196314e-01
4.749999999999999778e-01 -4.763139720814410505e-01
4.750000000000000888e-01 -2.165063509461093993e-01
4.750000000000001998e-01 4.330127018922216853e-02
4.750000000000003109e-01 3.031088913245537642e-01
7.000000000000000666e-01 -3.464101615137752388e-01
7.000000000000001776e-01 -8.660254037844367092e-02
7.000000000000002887e-01 1.732050807568879525e-01
9.250000000000002665e-01 -2.165063509461093716e-01
9.250000000000004885e-01 4.330127018922221710e-02
1.150000000000000355e+00 -8.660254037844382358e-02
答案 0 :(得分:1)
我可以通过matplotlib v1.3确认这个错误(matplotlib.delaunay已知会受到这些问题的影响),但现在使用更强大的库qhull时不能使用当前的master。
https://github.com/matplotlib/matplotlib/pull/2504
所以我很快就会用v1.4版本来解决这个问题。
在当前大师获得的图表下方。