Ticket #12414: trac-12414-defaultcolor.patch

File trac-12414-defaultcolor.patch, 11.5 KB (added by jason, 8 years ago)
  • sage/plot/arc.py

    # HG changeset patch
    # User Jason Grout <jason.grout@drake.edu>
    # Date 1328210093 21600
    # Node ID 91d23918f03dbbfe5ffa91d4f9517193ba63be4b
    # Parent  975c8f8c9f67da7a1430ba93946fae81a634691b
    Make a sage.plot.colors.DEFAULTCOLOR variable that is the default color for plots, lines, text, etc.
    
    diff --git a/sage/plot/arc.py b/sage/plot/arc.py
    a b  
    285285        raise NotImplementedError
    286286
    287287@rename_keyword(color='rgbcolor')
    288 @options(alpha=1, thickness=1, linestyle='solid', zorder=5,rgbcolor='blue',
     288@options(alpha=1, thickness=1, linestyle='solid', zorder=5,rgbcolor=None,
    289289         aspect_ratio=1.0)
    290290def arc(center, r1, r2=None, angle=0.0, sector=(0.0,2*pi), **options):
    291291    r"""
  • sage/plot/arrow.py

    diff --git a/sage/plot/arrow.py b/sage/plot/arrow.py
    a b  
    344344        return arrow3d(tailpoint, headpoint, **kwds)
    345345
    346346@rename_keyword(color='rgbcolor')
    347 @options(width=2, rgbcolor=(0,0,1),zorder=2, head = 1, linestyle='solid', legend_label=None)
     347@options(width=2, rgbcolor=None, zorder=2, head = 1, linestyle='solid', legend_label=None)
    348348def arrow2d(tailpoint=None, headpoint=None, path=None, **options):
    349349    """
    350350    If tailpoint and headpoint are provided, returns an arrow from (xmin, ymin)
  • sage/plot/bar_chart.py

    diff --git a/sage/plot/bar_chart.py b/sage/plot/bar_chart.py
    a b  
    2121from sage.plot.primitive import GraphicPrimitive
    2222from sage.plot.plot import minmax_data, Graphics
    2323from sage.misc.decorators import options, rename_keyword
     24from sage.plot.colors import to_mpl_color
    2425
    2526#TODO: make bar_chart more general
    2627class BarChart(GraphicPrimitive):
     
    109110            sage: bar_chart([1,2,10])
    110111        """
    111112        options = self.options()
    112         color = options['rgbcolor']
     113        color = to_mpl_color(options['rgbcolor'])
    113114        width = float(options['width'])
    114115        # it is critical to make NumPy arrays of type float below,
    115116        # or bar will go boom:
     
    119120        subplot.bar(ind, datalist, color=color, width=width, label=options['legend_label'])
    120121
    121122@rename_keyword(color='rgbcolor')
    122 @options(width=0.5, rgbcolor=(0,0,1), legend_label=None, aspect_ratio='automatic')
     123@options(width=0.5, rgbcolor=None, legend_label=None, aspect_ratio='automatic')
    123124def bar_chart(datalist, **options):
    124125    """
    125126    A bar chart of (currently) one list of numerical data.
  • sage/plot/colors.py

    diff --git a/sage/plot/colors.py b/sage/plot/colors.py
    a b  
    4040#                  http://www.gnu.org/licenses/
    4141#*****************************************************************************
    4242
     43DEFAULTCOLOR='blue'
     44
    4345import math
    4446import collections
    4547from colorsys import hsv_to_rgb, hls_to_rgb, rgb_to_hsv, rgb_to_hls
     
    266268        raise ValueError("color hex string (= '%s') must have length 3 or 6" % h)
    267269    return tuple([int(h[i:i + 2], base=16) / float(255) for i in [0, 2, 4]])
    268270
    269 
    270271def rgbcolor(c, space='rgb'):
    271272    """
    272273    Convert a color (string, tuple, list, or :class:`Color`) to a
     
    276277    INPUT:
    277278
    278279    - ``c`` - a :class:`Color` instance, string (name or HTML hex),
    279       3-tuple, or 3-list; the color to convert
     280      3-tuple, or 3-list; the color to convert.  If None, then the
     281      color given by sage.plot.colors.DEFAULTCOLOR is returned.
    280282
    281283    - ``space`` - a string (default: 'rgb'); the color space
    282284      coordinate system (other choices are 'hsl', 'hls', and 'hsv') in
     
    330332        ...
    331333        ValueError: color list or tuple '[0.400000000000000, 0.100000000000000]' must have 3 entries, one for each RGB, HSV, HLS, or HSL channel
    332334    """
     335    if c is None:
     336        c = DEFAULTCOLOR
    333337    if isinstance(c, Color):
    334338        return c.rgb()
    335339
  • sage/plot/disk.py

    diff --git a/sage/plot/disk.py b/sage/plot/disk.py
    a b  
    220220            return Line(xdata, ydata, options).plot3d().translate((0,0,z))
    221221
    222222@rename_keyword(color='rgbcolor')
    223 @options(alpha=1, fill=True, rgbcolor=(0,0,1), thickness=0, legend_label=None,
     223@options(alpha=1, fill=True, rgbcolor=None, thickness=0, legend_label=None,
    224224         aspect_ratio=1.0)
    225225def disk(point, radius, angle, **options):
    226226    r"""
  • sage/plot/line.py

    diff --git a/sage/plot/line.py b/sage/plot/line.py
    a b  
    282282
    283283   
    284284@rename_keyword(color='rgbcolor')
    285 @options(alpha=1, rgbcolor=(0,0,1), thickness=1, legend_label=None, aspect_ratio ='automatic')
     285@options(alpha=1, rgbcolor=None, thickness=1, legend_label=None, aspect_ratio ='automatic')
    286286def line2d(points, **options):
    287287    r"""
    288288    Create the line through the given list of points.
  • sage/plot/plot.py

    diff --git a/sage/plot/plot.py b/sage/plot/plot.py
    a b  
    194194    ...
    195195    sage: P.show(ymin=-pi,ymax=pi)
    196196
     197We can change the default color for many graphics objects::
     198
     199    sage: old_default=sage.plot.colors.DEFAULTCOLOR
     200    sage: sage.plot.colors.DEFAULTCOLOR='black'
     201    sage: plot(x^2,(x,0,1))+text('$x^2$',(0.5,0.5))
     202    sage: sage.plot.colors.DEFAULTCOLOR=old_default
     203
    197204PYX EXAMPLES: These are some examples of plots similar to some of
    198205the plots in the PyX (http://pyx.sourceforge.net) documentation:
    199206
     
    27232730    return xdata, ydata
    27242731
    27252732@rename_keyword(color='rgbcolor')
    2726 @options(alpha=1, thickness=1, fill=False, fillcolor='automatic', fillalpha=0.5, rgbcolor=(0,0,1), plot_points=200,
     2733@options(alpha=1, thickness=1, fill=False, fillcolor='automatic', fillalpha=0.5, rgbcolor=None, plot_points=200,
    27272734         adaptive_tolerance=0.01, adaptive_recursion=5, detect_poles = False, exclude = None, legend_label=None,
    27282735         __original_opts=True, aspect_ratio='automatic')
    27292736def plot(funcs, *args, **kwds):
  • sage/plot/plot3d/base.pyx

    diff --git a/sage/plot/plot3d/base.pyx b/sage/plot/plot3d/base.pyx
    a b  
    763763            set([])
    764764
    765765            sage: G = tetrahedron(color='red') + tetrahedron(color='yellow') + tetrahedron(color='red', opacity=0.5)
    766             sage: [t for t in G.texture_set() if t.color == colors.red] # we should have two red textures
     766            sage: [t for t in G.texture_set() if t.color == colors.red.rgb()] # we should have two red textures
    767767            [Texture(texture..., red, ff0000), Texture(texture..., red, ff0000)]
    768             sage: [t for t in G.texture_set() if t.color == colors.yellow] # ...and one yellow
     768            sage: [t for t in G.texture_set() if t.color == colors.yellow.rgb()] # ...and one yellow
    769769            [Texture(texture..., yellow, ffff00)]
    770770        """
    771771        return set()
     
    14161416        EXAMPLES::
    14171417
    14181418            sage: G = sphere(color='red') + sphere(color='yellow')
    1419             sage: [t for t in G.texture_set() if t.color == colors.red] # one red texture
     1419            sage: [t for t in G.texture_set() if t.color == colors.red.rgb()] # one red texture
    14201420            [Texture(texture..., red, ff0000)]
    1421             sage: [t for t in G.texture_set() if t.color == colors.yellow] # one yellow texture
     1421            sage: [t for t in G.texture_set() if t.color == colors.yellow.rgb()] # one yellow texture
    14221422            [Texture(texture..., yellow, ffff00)]
    14231423
    14241424            sage: T = sage.plot.plot3d.texture.Texture('blue'); T
  • sage/plot/plot3d/texture.py

    diff --git a/sage/plot/plot3d/texture.py b/sage/plot/plot3d/texture.py
    a b  
    1616However, one can access these textures in the following manner::
    1717
    1818    sage: G = tetrahedron(color='red') + tetrahedron(color='yellow') + tetrahedron(color='red', opacity=0.5)
    19     sage: [t for t in G.texture_set() if t.color == colors.red] # we should have two red textures
     19    sage: [t for t in G.texture_set() if t.color == colors.red.rgb()] # we should have two red textures
    2020    [Texture(texture..., red, ff0000), Texture(texture..., red, ff0000)]
    21     sage: [t for t in G.texture_set() if t.color == colors.yellow] # ...and one yellow
     21    sage: [t for t in G.texture_set() if t.color == colors.yellow.rgb()] # ...and one yellow
    2222    [Texture(texture..., yellow, ffff00)]
    2323
    2424And the Texture objects keep track of all their data::
     
    131131        Texture(texture..., 6666ff)
    132132        sage: Texture(shininess=0.3)
    133133        Texture(texture..., 6666ff)
    134         sage: Texture(ambiant=0.7)
     134        sage: Texture(ambient=0.7)
    135135        Texture(texture..., 6666ff)
    136136    """
    137137    if isinstance(id, Texture_class):
     
    167167    r"""
    168168    Parses the color.
    169169   
    170     It transforms a valid color string into a color object and
    171     a color object into an RBG tuple of length 3. Otherwise,
    172     it multiplies the info by the base color.
     170    It transforms a valid color description into an RBG tuple of
     171    length 3. Otherwise, it multiplies the info by the base color.
    173172
    174173    INPUT:
    175174
     
    178177
    179178    OUTPUT:
    180179
    181     A tuple or color.
     180    An RGB tuple.
    182181
    183182    EXAMPLES:
    184183
     
    192191    From a valid color str::
    193192
    194193        sage: parse_color('red')
    195         RGB color (1.0, 0.0, 0.0)
     194        (1.0, 0.0, 0.0)
    196195
    197196    From a non valid color str::
    198197
     
    207206        sage: parse_color(opacity, base=(.2,.3,.4))
    208207        (2.0, 3.0, 4.0)
    209208    """
    210     if isinstance(info, Color):
    211         return info.rgb()
    212     elif isinstance(info, str):
    213         try:
    214             return colors[info]
    215         except KeyError:
    216             raise ValueError, "unknown color '%s'"%info
    217     else:
    218         r, g, b = base
    219         # We don't want to lose the data when we split it into its respective components.
    220         if not r: r = 1e-5
    221         if not g: g = 1e-5
    222         if not b: b = 1e-5
    223         return (float(info*r), float(info*g), float(info*b))
     209    from sage.plot.colors import to_mpl_color
     210    try:
     211        info=float(info)
     212    except (ValueError, TypeError):
     213        return to_mpl_color(info)
    224214
     215    r, g, b = to_mpl_color(base)
     216    # We don't want to lose the data when we split it into its respective components.
     217    if not r: r = 1e-5
     218    if not g: g = 1e-5
     219    if not b: b = 1e-5
     220    return (float(info*r), float(info*g), float(info*b))
    225221
    226222class Texture_class(SageObject):
    227223    r"""
  • sage/plot/point.py

    diff --git a/sage/plot/point.py b/sage/plot/point.py
    a b  
    312312        return point3d(points, **kwds)
    313313
    314314@rename_keyword(color='rgbcolor', pointsize='size')
    315 @options(alpha=1, size=10, faceted=False, rgbcolor=(0,0,1), legend_label=None, aspect_ratio='automatic')
     315@options(alpha=1, size=10, faceted=False, rgbcolor=None, legend_label=None, aspect_ratio='automatic')
    316316def point2d(points, **options):
    317317    r"""
    318318    A point of size ``size`` defined by point = `(x,y)`.
  • sage/plot/polygon.py

    diff --git a/sage/plot/polygon.py b/sage/plot/polygon.py
    a b  
    275275        return polygon3d(points, **options)
    276276
    277277@rename_keyword(color='rgbcolor')
    278 @options(alpha=1, rgbcolor=(0,0,1), thickness=0, legend_label=None, aspect_ratio=1.0)
     278@options(alpha=1, rgbcolor=None, thickness=0, legend_label=None, aspect_ratio=1.0)
    279279def polygon2d(points, **options):
    280280    r"""
    281281    Returns a polygon defined by ``points``.
  • sage/plot/text.py

    diff --git a/sage/plot/text.py b/sage/plot/text.py
    a b  
    178178
    179179
    180180@rename_keyword(color='rgbcolor')
    181 @options(fontsize=10, rgbcolor=(0,0,1), horizontal_alignment='center',
     181@options(fontsize=10, rgbcolor=None, horizontal_alignment='center',
    182182         vertical_alignment='center', axis_coords=False, clip=False)
    183183def text(string, xy, **options):
    184184    r"""