diff -Naur matplotlib-0.90.1-old/lib/matplotlib/backends/backend_svg.py matplotlib-0.90.1-newsvg/lib/matplotlib/backends/backend_svg.py --- matplotlib-0.90.1-old/lib/matplotlib/backends/backend_svg.py 2007-06-02 05:14:34.000000000 -0400 +++ matplotlib-0.90.1-newsvg/lib/matplotlib/backends/backend_svg.py 2007-07-09 20:08:27.000000000 -0400 @@ -206,11 +206,39 @@ if len(x)==0: return if len(x)!=len(y): raise ValueError('x and y must be the same length') - + y = self.height - y - details = ['d="M %f,%f' % (x[0], y[0])] - xys = zip(x[1:], y[1:]) - details.extend(['L %f,%f' % tup for tup in xys]) + + bound = 3*gc.get_linewidth() # *3 just in case... + maxX = self.width + bound + minX = 0 - bound + maxY = self.height + bound + minY = 0 - bound + + seqData = zip(x[:-1], x[1:], y[:-1], y[1:]) + drop = [ (x1 < minX and x2 < minX) or (x1 > maxX and x2 > maxX) or + (y1 < minY and y2 < minY) or (y1 > maxY and y2 > maxY) + for x1,x2,y1,y2 in seqData] + + startpos = 0 + try: startpos = drop.index(False) + except ValueError: return #all lines were culled + + try: + xys = zip(x, y) + details = ['d="'] + while True: + noDrop = True + endpos = drop.index(True, startpos) + details.append('M %f,%f' % xys[startpos]) + details.extend(['L %f,%f' % tup for tup in xys[startpos+1:endpos]]) + noDrop = False + startpos = drop.index(False, endpos) + except ValueError: + if noDrop: + details.append('M %f,%f' % xys[startpos]) + details.extend(['L %f,%f' % tup for tup in xys[startpos+1:]]) + details.append('"') details = ' '.join(details) self._draw_svg_element('path', details, gc, None) @@ -220,6 +248,18 @@ self.draw_arc(gc, gc.get_rgb(), x, y, 1, 0, 0, 0, 0) def draw_polygon(self, gc, rgbFace, points): + bound = 3*gc.get_linewidth() + maxX = self.width + bound + minX = 0 - bound + maxY = self.height + bound + minY = 0 - bound + + drop = [ (x < minX) or (x > maxX) or + (y < minY) or (y > maxY) for x, y in points] + + if(all(drop)): + return + details = 'points = "%s"' % ' '.join(['%f,%f'%(x,self.height-y) for x, y in points]) self._draw_svg_element('polygon', details, gc, rgbFace)