Dear matplotlib-users,
I'd like to report a bug in Polygon, which is crashing with an unhelpful error message where an exception would be appropriate. The problem occurs when you feed Polygon an Nx2 array instead of an N-length list of 2-tuples. This is on my PPC OSX system, with everything freshly checked out from SVN (should the matplotlib version still be 0.87.4?).
Versions:
In [152]: numpy.__version__
Out[152]: '1.1.2881'
In [154]: matplotlib.__version__
Out[154]: '0.87.4'
Code:
import pylab, numpy
theta = numpy.pi/4*numpy.arange(9,dtype=float)
x = numpy.cos(theta)
y = numpy.sin(theta)
# The following line works
#p = pylab.Polygon(zip(x,y))
# The following line causes a crash
p = pylab.Polygon(numpy.vstack((x,y)).T)
ax = pylab.subplot(111)
ax.add_patch(p)
pylab.show()
Output:
In [155]: run plot_polygon.py
···
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent call last)
/Users/nvf/Documents/S.M. Thesis/plot_polygon.py
10
11 ax = pylab.subplot(111)
---> 12 ax.add_patch(p)
13 pylab.show() 14
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axes.py in add_patch(self, p)
899 p.get_transform(), p.get_verts())
900 #for x,y in xys: print x,y
--> 901 self.update_datalim(xys)
902 self.patches.append(p)
903
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axes.py in update_datalim(self, xys)
913 # Otherwise, it will compute the bounds of it's current data
914 # and the data in xydata
--> 915 self.dataLim.update(xys, -1)
916
917
TypeError: CXX : Error creating object of type N2Py5TupleE
WARNING: Failure executing file: <plot_polygon.py>
Instead of converting from crash to exception, though, would it be possible to make it accept an Nx2 array?
Please at least cc me in any replies, as I am not subscribed to this list.
Thanks,
Nick