Ticket #12936: sage-trac_12936.patch

File sage-trac_12936.patch, 2.4 KB (added by mjo, 10 years ago)

Merge plot options the same way we do other keyword arguments.

  • sage/plot/graphics.py

    # HG changeset patch
    # User Michael Orlitzky <michael@orlitzky.com>
    # Date 1336700132 14400
    # Node ID a4e9c32259bd7f42c4f066a8dd5185819d824fc3
    # Parent  9e488f0b4280c1bb10e5c2b08a797181d42de37a
    Trac #12936: Preserve legend options when adding plots.
    
    diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
    a b  
    961961        aspect ratio is chosen, with 'automatic' being overridden by a
    962962        numeric aspect ratio.
    963963
    964         If one of the graphics object is set to show a legend, then the
    965         resulting object will also be set to show a legend.  None of the
    966         legend options are carried over.
     964        If one of the graphics object is set to show a legend, then
     965        the resulting object will also be set to show a legend. Legend
     966        options are propagated if set. If the same legend option is
     967        present in both arguments, the latter value is used.
    967968
    968969        EXAMPLES::
    969970       
     
    983984            sage: g2.set_aspect_ratio(3)
    984985            sage: (g1+g2).aspect_ratio()
    985986            3.0
     987
     988        As are legend options, :trac:`12936`::
     989
     990            sage: p1 = plot(x, x, 0, 1)
     991            sage: p2 = p1
     992            sage: p1.set_legend_options(back_color = 'white')
     993            sage: p2.set_legend_options(shadow = True)
     994            sage: p3 = p1 + p2
     995            sage: p3._Graphics__legend_opts
     996            {'shadow': True, 'back_color': 'white'}
     997
     998        If the same legend option is specified more than once, the
     999        latter takes precedence::
     1000
     1001            sage: p1 = plot(x, x, 0, 1)
     1002            sage: p2 = p1
     1003            sage: p1.set_legend_options(shadow = True)
     1004            sage: p2.set_legend_options(shadow = False)
     1005            sage: p3 = p1 + p2
     1006            sage: p3._Graphics__legend_opts
     1007            {'shadow': False}
     1008
    9861009        """
    9871010        if isinstance(other, int) and other == 0:
    9881011            return self
     
    9961019        g.__show_legend = self.__show_legend or other.__show_legend
    9971020        g._extra_kwds.update(self._extra_kwds)
    9981021        g._extra_kwds.update(other._extra_kwds)
     1022        g._Graphics__legend_opts.update(self._Graphics__legend_opts)
     1023        g._Graphics__legend_opts.update(other._Graphics__legend_opts)
    9991024        if self.aspect_ratio()=='automatic':
    10001025            g.set_aspect_ratio(other.aspect_ratio())
    10011026        elif other.aspect_ratio()=='automatic':