Ticket #14112: trac_14112-allow_individual_axes.patch

File trac_14112-allow_individual_axes.patch, 4.4 KB (added by ppurka, 8 years ago)

Apply to devel/sage

  • sage/plot/graphics.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1360808170 -28800
    # Node ID 90f4a1552967d79adfb51047a41353320da5b83a
    # Parent  aa4e56d08bc563cf3484860e88589cf57062e8df
    allow to turn off axes selectively
    
    diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
    a b  
    12901290          high as it is wide.  If set to ``'automatic'``, the aspect ratio
    12911291          is determined by ``figsize`` and the picture fills the figure.
    12921292
    1293         - ``axes`` - (default: True)
    1294        
     1293        - ``axes`` - (default: True) Turn the axes on or off. This can be
     1294          also provided a list or tuple of two booleans to turn on or off
     1295          the horizontal or vertical axis selectively. The first boolean
     1296          controls whether the horizontal axis is shown and the second
     1297          boolean controls the vertical axis.
     1298
    12951299        - ``axes_labels`` - (default: None) list (or tuple) of two
    12961300          strings; the first is used as the label for the horizontal
    12971301          axis, and the second for the vertical axis.
    1298                            
     1302
    12991303        - ``fontsize`` - (default: current setting -- 10) positive
    13001304          integer; used for axes labels; if you make this very large,
    13011305          you may have to increase figsize to see all labels.
     
    14671471
    14681472            sage: show(plot(sin,-4,4), axes=False)
    14691473
     1474        It is possible to turn off the drawing of a specific axis. Below, we
     1475        turn off the horizontal axis::
     1476
     1477            sage: show(plot(sin,-4,4), axes=[False, True])
     1478
    14701479        You can also label the axes.  Putting something in dollar
    14711480        signs formats it as a mathematical expression::
    14721481
     
    21232132        if axes is None:
    21242133            axes = self._show_axes
    21252134
     2135        if isinstance(axes, (tuple, list)):
     2136            if len(axes) != 2:
     2137                raise ValueError("axes must either be a boolean, or a tuple "
     2138                                 "or list of exactly two booleans")
     2139            x_axes, y_axes = axes
     2140            axes = x_axes or y_axes
     2141        else:
     2142            x_axes = y_axes = axes
     2143
    21262144        from matplotlib.figure import Figure
    21272145        from matplotlib import rcParams
    21282146        self.fontsize(fontsize)
     
    21862204
    21872205        locator_options=dict(nbins=9,steps=[1,2,5,10],integer=ticks_integer)
    21882206
    2189         if axes is None:
    2190             axes = self._show_axes
    2191 
    21922207        for spine in subplot.spines.values():
    21932208            spine.set_color(self._axes_color)
    21942209            spine.set_linewidth(self._axes_width)
     
    22092224           
    22102225            subplot.set_frame_on(True)
    22112226            if axes and xscale == 'linear' and yscale == 'linear':
    2212                 if (ymin<=0 and ymax>=0) or (ymax<=0 and ymin>=0):
     2227                if x_axes and ((ymin<=0 and ymax>=0) or (ymax<=0 and ymin>=0)):
    22132228                    subplot.axhline(color=self._axes_color,
    22142229                                    linewidth=self._axes_width)
    2215                 if (xmin<=0 and xmax>=0) or (xmax<=0 and xmin>=0):
     2230                if y_axes and ((xmin<=0 and xmax>=0) or (xmax<=0 and xmin>=0)):
    22162231                    subplot.axvline(color=self._axes_color,
    22172232                                    linewidth=self._axes_width)
    22182233
     
    22232238            # flips the axis horizontally. Hence we need to check for both
    22242239            # the possibilities in the if statements below. Similar
    22252240            # comments hold for ymin and ymax.
    2226             if xscale == 'log':
     2241            if not y_axes:
     2242                subplot.spines['left'].set_visible(False)
     2243                subplot.spines['right'].set_visible(False)
     2244                ticks = (ticks[0], [])
     2245                yaxis='left'
     2246            elif xscale == 'log':
    22272247                if xmax > xmin:
    22282248                    subplot.spines['right'].set_visible(False)
    22292249                    subplot.spines['left'].set_position(('outward',10))
     
    22562276                ymiddle=True
    22572277                yaxis='left'
    22582278
    2259             if yscale == 'log':
     2279            if not x_axes:
     2280                subplot.spines['top'].set_visible(False)
     2281                subplot.spines['bottom'].set_visible(False)
     2282                ticks = ([], ticks[1])
     2283                xaxis='bottom'
     2284            elif yscale == 'log':
    22602285                if ymax > ymin:
    22612286                    subplot.spines['top'].set_visible(False)
    22622287                    subplot.spines['bottom'].set_position(('outward',10))