Ticket #14580: trac_14580-more-colors-rebased.patch

File trac_14580-more-colors-rebased.patch, 10.4 KB (added by ppurka, 6 years ago)

Rebased against #13834

  • sage/plot/arrow.py

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1371595255 14400
    # Node ID c022f2d2536f5e708b4daf2a780a0beb99c01c03
    # Parent  a2714dfdc18da0e4eafd0b843c65de04a1660252
    Trac 14580 - more legend colors in different plot types
    
    diff --git a/sage/plot/arrow.py b/sage/plot/arrow.py
    a b  
    7676             ('arrowstyle', 'todo'),
    7777             ('head', '2-d only: Which end of the path to draw the head (one of 0 (start), 1 (end) or 2 (both)'),
    7878             ('hue', 'The color given as a hue.'),
     79             ('legend_color', 'The color of the legend text.'),
    7980             ('legend_label', 'The label for this item in the legend.'),
    8081             ('linestyle', "2d only: The style of the line, which is one of
    8182             'dashed', 'dotted', 'solid', 'dashdot', or '--', ':', '-', '-.',
     
    8889                'rgbcolor':'The color as an RGB tuple.',
    8990                'hue':'The color given as a hue.',
    9091                'legend_label':'The label for this item in the legend.',
     92                'legend_color':'The color of the legend text.',
    9193                'arrowstyle': 'todo',
    9294                'arrowsize':'The size of the arrowhead',
    9395                'zorder':'2-d only: The layer level in which to draw',
     
    207209             ('head',
    208210             '2-d only: Which end of the path to draw the head (one of 0 (start), 1 (end) or 2 (both)'),
    209211             ('hue', 'The color given as a hue.'),
     212             ('legend_color', 'The color of the legend text.'),
    210213             ('legend_label', 'The label for this item in the legend.'),
    211214             ('linestyle',
    212215             "2d only: The style of the line, which is one of 'dashed',
     
    222225                'arrowshorten':'The length in points to shorten the arrow.',
    223226                'arrowsize':'The size of the arrowhead',
    224227                'legend_label':'The label for this item in the legend.',
     228                'legend_color':'The color of the legend text.',
    225229                'zorder':'2-d only: The layer level in which to draw',
    226230                'head':'2-d only: Which end of the path to draw the head (one of 0 (start), 1 (end) or 2 (both)',
    227231                'linestyle':"2d only: The style of the line, which is one of "
     
    486490
    487491    - ``legend_label`` - the label for this item in the legend
    488492
     493    - ``legend_color`` - the color for the legend label
     494
    489495    - ``zorder`` - the layer level to draw the arrow-- note that this is ignored in 3D
    490496      plotting.
    491497
     
    523529
    524530        sage: arrow2d(headpoint=None, tailpoint=None)
    525531
    526 
    527532    We can also draw an arrow with a legend::
    528533
    529         sage: arrow((0,0), (0,2), legend_label='up')
     534        sage: arrow((0,0), (0,2), legend_label='up', legend_color='purple')
    530535
    531536    Extra options will get passed on to show(), as long as they are valid::
    532537
     
    549554        raise TypeError('Arrow requires either both headpoint and tailpoint or a path parameter.')
    550555    if options['legend_label']:
    551556        g.legend(True)
     557        g._legend_colors = [options['legend_color']]
    552558    return g
  • sage/plot/circle.py

    diff --git a/sage/plot/circle.py b/sage/plot/circle.py
    a b  
    110110        return {'alpha':'How transparent the figure is.',
    111111                'fill':'Whether or not to fill the circle.',
    112112                'legend_label':'The label for this item in the legend.',
     113                'legend_color':'The color of the legend text.',
    113114                'thickness':'How thick the border of the circle is.',
    114115                'edgecolor':'2D only: The color of the edge as an RGB tuple.',
    115116                'facecolor':'2D only: The color of the face as an RGB tuple.',
     
    218219
    219220@rename_keyword(color='rgbcolor')
    220221@options(alpha=1, fill=False, thickness=1, edgecolor='blue', facecolor='blue', linestyle='solid',
    221          zorder=5, legend_label=None, clip=True, aspect_ratio=1.0)
     222         zorder=5, legend_label=None, legend_color=None, clip=True, aspect_ratio=1.0)
    222223def circle(center, radius, **options):
    223224    """
    224225    Return a circle at a point center = `(x,y)` (or `(x,y,z)` and
     
    247248
    248249    - ``legend_label`` - the label for this item in the legend
    249250
     251    - ``legend_color`` - the color for the legend label
     252
    250253    EXAMPLES:
    251254
    252255    The default color is blue, the default linestyle is solid, but this is easy to change::
     
    299302
    300303        sage: circle((2,3), 1, fill=True, edgecolor='blue', rgbcolor='green', hue=.8)
    301304
    302     And a circle with a legend::
     305    And circles with legends::
    303306
    304307        sage: circle((4,5), 1, rgbcolor='yellow', fill=True, legend_label='the sun').show(xmin=0, ymin=0)
    305308
     309    ::
     310
     311        sage: circle((4,5), 1, legend_label='the sun', legend_color='yellow').show(xmin=0, ymin=0)
     312
    306313    Extra options will get passed on to show(), as long as they are valid::
    307314
    308315        sage: circle((0, 0), 2, figsize=[10,10]) # That circle is huge!
     
    341348    g.add_primitive(Circle(center[0], center[1], radius, options))
    342349    if options['legend_label']:
    343350        g.legend(True)
     351        g._legend_colors = [options['legend_color']]
    344352    if len(center)==2:
    345353        return g
    346354    elif len(center)==3:
  • sage/plot/disk.py

    diff --git a/sage/plot/disk.py b/sage/plot/disk.py
    a b  
    123123        return {'alpha':'How transparent the figure is.',
    124124                'fill':'Whether or not to fill the disk.',
    125125                'legend_label':'The label for this item in the legend.',
     126                'legend_color':'The color of the legend text.',
    126127                'thickness':'How thick the border of the disk is.',
    127128                'rgbcolor':'The color as an RGB tuple.',
    128129                'hue':'The color given as a hue.',
     
    283284
    284285    TESTS:
    285286
     287    Testing that legend labels work right::
     288
     289        sage: disk((2,4), 3, (pi/8, pi/4), hue=1, legend_label='disk', legend_color='blue')
     290
    286291    We cannot currently plot disks in more than three dimensions::
    287292
    288293        sage: d = disk((1,1,1,1), 1, (0,pi))
     
    305310    g.add_primitive(Disk(point, radius, angle, options))
    306311    if options['legend_label']:
    307312        g.legend(True)
     313        g._legend_colors = [options['legend_color']]
    308314    if len(point)==2:
    309315        return g
    310316    elif len(point)==3:
  • sage/plot/ellipse.py

    diff --git a/sage/plot/ellipse.py b/sage/plot/ellipse.py
    a b  
    144144        return {'alpha':'How transparent the figure is.',
    145145                'fill': 'Whether or not to fill the ellipse.',
    146146                'legend_label':'The label for this item in the legend.',
     147                'legend_color':'The color of the legend text.',
    147148                'thickness':'How thick the border of the ellipse is.',
    148149                'edgecolor':'2D only: The color of the edge as an RGB tuple.',
    149150                'facecolor':'2D only: The color of the face as an RGB tuple.',
     
    219220
    220221@rename_keyword(color='rgbcolor')
    221222@options(alpha=1, fill=False, thickness=1, edgecolor='blue', facecolor='blue', linestyle='solid', zorder=5,
    222          aspect_ratio=1.0, legend_label=None)
     223         aspect_ratio=1.0, legend_label=None, legend_color=None)
    223224def ellipse(center, r1, r2, angle=0, **options):
    224225    """
    225226    Return an ellipse centered at a point center = ``(x,y)`` with radii =
     
    254255    - ``rgbcolor`` - 2D or 3D plotting.  This option overrides
    255256      ``edgecolor`` and ``facecolor`` for 2D plotting.
    256257
     258    - ``legend_label`` - the label for this item in the legend
     259
     260    - ``legend_color`` - the color for the legend label
     261
    257262    EXAMPLES:
    258263
    259264    An ellipse centered at (0,0) with major and minor axes of lengths 2 and 1.
     
    286291        Traceback (most recent call last):
    287292        ...
    288293        NotImplementedError: plotting ellipse in 3D is not implemented
     294
     295    We can also give ellipses a legend::
     296
     297        sage: ellipse((0,0),2,1,legend_label="My ellipse", legend_color='green')
    289298    """
    290299    from sage.plot.all import Graphics
    291300    g = Graphics()
     
    302311    g.add_primitive(Ellipse(center[0],center[1],r1,r2,angle,options))
    303312    if options['legend_label']:
    304313        g.legend(True)
     314        g._legend_colors = [options['legend_color']]
    305315    if len(center)==2:
    306316        return g
    307317    elif len(center)==3:
  • sage/plot/point.py

    diff --git a/sage/plot/point.py b/sage/plot/point.py
    a b  
    354354
    355355        sage: point((0,0), rgbcolor='black', pointsize=40, legend_label='origin')
    356356
     357    The legend can be colored::
     358
     359        sage: P = points([(0,0),(1,0)], pointsize=40, legend_label='origin', legend_color='red')
     360        sage: P + plot(x^2,(x,0,1), legend_label='plot', legend_color='green')
     361
    357362    Extra options will get passed on to show(), as long as they are valid::
    358363
    359364        sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)], frame=True)
  • sage/plot/polygon.py

    diff --git a/sage/plot/polygon.py b/sage/plot/polygon.py
    a b  
    147147                'thickness': 'How thick the border line is.',
    148148                'fill':'Whether or not to fill the polygon.',
    149149                'legend_label':'The label for this item in the legend.',
     150                'legend_color':'The color of the legend text.',
    150151                'rgbcolor':'The color as an RGB tuple.',
    151152                'hue':'The color given as a hue.',
    152153                'zorder':'The layer level in which to draw'}
     
    275276        return polygon3d(points, **options)
    276277
    277278@rename_keyword(color='rgbcolor')
    278 @options(alpha=1, rgbcolor=(0,0,1), thickness=None, legend_label=None, aspect_ratio=1.0, fill=True)
     279@options(alpha=1, rgbcolor=(0,0,1), thickness=None, legend_label=None, legend_color=None,
     280         aspect_ratio=1.0, fill=True)
    279281def polygon2d(points, **options):
    280282    r"""
    281283    Returns a 2-dimensional polygon defined by ``points``.
     
    347349        sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,100)]
    348350        sage: polygon2d(L, rgbcolor=(1,1/4,1/2))
    349351
     352    One can do the same one with a colored legend label::
     353
     354        sage: polygon2d(L, color='red', legend_label='For you!', legend_color='red')
     355
    350356    Polygons have a default aspect ratio of 1.0::
    351357
    352358        sage: polygon2d([[1,2], [5,6], [5,0]]).aspect_ratio()
     
    379385    g.add_primitive(Polygon(xdata, ydata, options))
    380386    if options['legend_label']:
    381387        g.legend(True)
     388        g._legend_colors = [options['legend_color']]
    382389    return g