Ticket #11677: 11677_polygon_fill_flat.patch

File 11677_polygon_fill_flat.patch, 2.7 KB (added by jdemeyer, 10 years ago)

Rebased to sage-5.0.beta1, apply only this

  • sage/plot/polygon.py

    # HG changeset patch
    # User Peter Story <peter.story@gordon.edu>
    # Date 1326233233 18000
    # Node ID e1a74f9f40df82804088512281b71a8a96bf778c
    # Parent  7b8d99242906b230cd18e1abd285aa9ac063776c
    Fixed fill argument, thickness now defaults to 1 when fill=False.
    
    diff --git a/sage/plot/polygon.py b/sage/plot/polygon.py
    a b  
    166166        """
    167167        if options is None:
    168168            options = dict(self.options())
    169         if 'thickness' in options:
    170             del options['thickness']
    171         if 'zorder' in options:
    172             del options['zorder']
    173         if 'legend_label' in options:
    174             del options['legend_label']
     169        for o in ['thickness', 'zorder', 'legend_label', 'fill']:
     170            options.pop(o, None)
    175171        return GraphicPrimitive_xydata._plot3d_options(self, options)
    176172
    177173    def plot3d(self, z=0, **kwds):
     
    243239        a = float(options['alpha'])
    244240        z = int(options.pop('zorder', 1))
    245241        p.set_alpha(a)
     242        f = options.pop('fill')
     243        p.set_fill(f)
    246244        c = to_mpl_color(options['rgbcolor'])
    247245        p.set_edgecolor(c)
    248246        p.set_facecolor(c)
     
    275273        return polygon3d(points, **options)
    276274
    277275@rename_keyword(color='rgbcolor')
    278 @options(alpha=1, rgbcolor=(0,0,1), thickness=0, legend_label=None, aspect_ratio=1.0)
     276@options(alpha=1, rgbcolor=(0,0,1), thickness=None, legend_label=None, aspect_ratio=1.0, fill=True)
    279277def polygon2d(points, **options):
    280278    r"""
    281     Returns a polygon defined by ``points``.
     279    Returns a 2-dimensional polygon defined by ``points``.
    282280
    283281    Type ``polygon.options`` for a dictionary of the default
    284282    options for polygons.  You can change this to change
     
    291289
    292290        sage: polygon2d([[1,2], [5,6], [5,0]], rgbcolor=(1,0,1))
    293291
     292    By default, polygons are filled in, but we can make them
     293    without a fill as well::
     294
     295        sage: polygon2d([[1,2], [5,6], [5,0]], fill=False)
     296
     297    In either case, the thickness of the border can be controlled::
     298
     299        sage: polygon2d([[1,2], [5,6], [5,0]], fill=False, thickness=4, color='orange')
     300
    294301    Some modern art -- a random polygon, with legend::
    295302
    296303        sage: v = [(randrange(-5,5), randrange(-5,5)) for _ in range(10)]
     
    349356   
    350357    """
    351358    from sage.plot.plot import xydata_from_point_list, Graphics
     359    if options["thickness"] is None:    # If the user did not specify thickness
     360        if options["fill"]:                 # If the user chose fill
     361            options["thickness"] = 0
     362        else:
     363            options["thickness"] = 1
    352364    xdata, ydata = xydata_from_point_list(points)
    353365    g = Graphics()
    354366    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))