Ticket #14580: trac_14580-more-colors.patch

File trac_14580-more-colors.patch, 10.6 KB (added by kcrisman, 6 years ago)
  • sage/plot/arrow.py

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1371595255 14400
    # Node ID c8ae052c0947dc46548f8ef75d7a4416f9886856
    # Parent  8d90ea6007c061eba51d1cf52cf23975567daf41
    Trac 14580 - more legend colors in different plot types
    
    diff --git a/sage/plot/arrow.py b/sage/plot/arrow.py
    a b  
    7575             [('arrowsize', 'The size of the arrowhead'),
    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)'),
    78              ('hue', 'The color given as a hue.'),
     78             ('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 'dashed', 'dotted', 'solid', 'dashdot'."),
    8182             ('rgbcolor', 'The color as an RGB tuple.'),
     
    8687                'rgbcolor':'The color as an RGB tuple.',
    8788                'hue':'The color given as a hue.',
    8889                'legend_label':'The label for this item in the legend.',
     90                'legend_color':'The color of the legend text.',
    8991                'arrowstyle': 'todo',
    9092                'linestyle': 'todo',
    9193                'arrowsize':'The size of the arrowhead',
     
    200202             ('arrowsize', 'The size of the arrowhead'),
    201203             ('head', '2-d only: Which end of the path to draw the head (one of 0 (start), 1 (end) or 2 (both)'),
    202204             ('hue', 'The color given as a hue.'),
     205             ('legend_color', 'The color of the legend text.'),
    203206             ('legend_label', 'The label for this item in the legend.'),
    204207             ('linestyle', "2d only: The style of the line, which is one of 'dashed', 'dotted', 'solid', 'dashdot'."),
    205208             ('rgbcolor', 'The color as an RGB tuple.'),
     
    212215                'arrowshorten':'The length in points to shorten the arrow.',
    213216                'arrowsize':'The size of the arrowhead',
    214217                'legend_label':'The label for this item in the legend.',
     218                'legend_color':'The color of the legend text.',
    215219                'zorder':'2-d only: The layer level in which to draw',
    216220                'head':'2-d only: Which end of the path to draw the head (one of 0 (start), 1 (end) or 2 (both)',
    217221                'linestyle':"2d only: The style of the line, which is one of 'dashed', 'dotted', 'solid', 'dashdot'."}
     
    398402
    399403    - ``legend_label`` - the label for this item in the legend
    400404
     405    - ``legend_color`` - the color for the legend label
     406
    401407    - ``zorder`` - the layer level to draw the arrow-- note that this is ignored in 3D
    402408      plotting.
    403409
     
    435441
    436442        sage: arrow2d(headpoint=None, tailpoint=None)
    437443
    438 
    439444    We can also draw an arrow with a legend::
    440445
    441         sage: arrow((0,0), (0,2), legend_label='up')
     446        sage: arrow((0,0), (0,2), legend_label='up', legend_color='purple')
    442447
    443448    Extra options will get passed on to show(), as long as they are valid::
    444449
     
    466471        raise TypeError('Arrow requires either both headpoint and tailpoint or a path parameter.')
    467472    if options['legend_label']:
    468473        g.legend(True)
     474        g._legend_colors = [options['legend_color']]
    469475    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.',
     
    214215
    215216@rename_keyword(color='rgbcolor')
    216217@options(alpha=1, fill=False, thickness=1, edgecolor='blue', facecolor='blue', linestyle='solid',
    217          zorder=5, legend_label=None, clip=True, aspect_ratio=1.0)
     218         zorder=5, legend_label=None, legend_color=None, clip=True, aspect_ratio=1.0)
    218219def circle(center, radius, **options):
    219220    """
    220221    Return a circle at a point center = `(x,y)` (or `(x,y,z)` and
     
    241242
    242243    - ``legend_label`` - the label for this item in the legend
    243244
     245    - ``legend_color`` - the color for the legend label
     246
    244247    EXAMPLES:
    245248
    246249    The default color is blue, but this is easy to change::
     
    293296
    294297        sage: circle((2,3), 1, fill=True, edgecolor='blue', rgbcolor='green', hue=.8)
    295298
    296     And a circle with a legend::
     299    And circles with legends::
    297300
    298301        sage: circle((4,5), 1, rgbcolor='yellow', fill=True, legend_label='the sun').show(xmin=0, ymin=0)
    299302
     303    ::
     304
     305        sage: circle((4,5), 1, legend_label='the sun', legend_color='yellow').show(xmin=0, ymin=0)
     306
    300307    Extra options will get passed on to show(), as long as they are valid::
    301308
    302309        sage: circle((0, 0), 2, figsize=[10,10]) # That circle is huge!
     
    335342    g.add_primitive(Circle(center[0], center[1], radius, options))
    336343    if options['legend_label']:
    337344        g.legend(True)
     345        g._legend_colors = [options['legend_color']]
    338346    if len(center)==2:
    339347        return g
    340348    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.',
     
    215216
    216217@rename_keyword(color='rgbcolor')
    217218@options(alpha=1, fill=False, thickness=1, edgecolor='blue', facecolor='blue', linestyle='solid', zorder=5,
    218          aspect_ratio=1.0, legend_label=None)
     219         aspect_ratio=1.0, legend_label=None, legend_color=None)
    219220def ellipse(center, r1, r2, angle=0, **options):
    220221    """
    221222    Return an ellipse centered at a point center = ``(x,y)`` with radii =
     
    248249    - ``rgbcolor`` - 2D or 3D plotting.  This option overrides
    249250      ``edgecolor`` and ``facecolor`` for 2D plotting.
    250251
     252    - ``legend_label`` - the label for this item in the legend
     253
     254    - ``legend_color`` - the color for the legend label
     255
    251256    EXAMPLES:
    252257
    253258    An ellipse centered at (0,0) with major and minor axes of lengths 2 and 1.
     
    279284        Traceback (most recent call last):
    280285        ...
    281286        NotImplementedError: plotting ellipse in 3D is not implemented
     287
     288    We can also give ellipses a legend::
     289
     290        sage: ellipse((0,0),2,1,legend_label="My ellipse", legend_color='green')
    282291    """
    283292    from sage.plot.all import Graphics
    284293    g = Graphics()
     
    295304    g.add_primitive(Ellipse(center[0],center[1],r1,r2,angle,options))
    296305    if options['legend_label']:
    297306        g.legend(True)
     307        g._legend_colors = [options['legend_color']]
    298308    if len(center)==2:
    299309        return g
    300310    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