Ticket #2517: plot_undefined.patch

File plot_undefined.patch, 2.8 KB (added by jason, 15 years ago)
  • sage/plot/plot.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1205530060 18000
    # Node ID f7af50a89a2133bfe1226be61baadd6d8fba1519
    # Parent  bd7d421e02671580f4392cdb86e42559dd973a8c
    Delete undefined values from the plot.
    
    diff -r bd7d421e0267 -r f7af50a89a21 sage/plot/plot.py
    a b class PlotFactory(GraphicPrimitiveFactor 
    33153315        sage: plot([sin(n*x) for n in [1..4]], (0, pi))
    33163316
    33173317
    3318     The function $\sin(1/x)$ wiggles wildtly near $0$, so the
     3318    The function $\sin(1/x)$ wiggles wildly near $0$, so the
    33193319    first plot below won't look perfect.  Sage adapts to this
    33203320    and plots extra points near the origin.
    33213321        sage: plot(sin(1/x), (x, -1, 1))
    class PlotFactory(GraphicPrimitiveFactor 
    33463346    We can change the line style to one of '--' (dashed), '-.' (dash dot),
    33473347    '-' (solid), 'steps', ':' (dotted):
    33483348        sage: plot(sin(x), 0, 10, linestyle='-.')
     3349
     3350    Sage currently ignores points that cannot be evaluated
     3351        sage: plot(-x*log(x), (x,0,1))
     3352        sage: plot(x^(1/3), (x,-1,1))
     3353
     3354    To plot the negative real cube root, use something like the following.
     3355        sage: plot(lambda x : RR(x).nth_root(3), (x,-1, 1) )
    33493356
    33503357    TESTS:
    33513358    We do not randomize the endpoints:
    class PlotFactory(GraphicPrimitiveFactor 
    33833390            elif n == 1:
    33843391                G = self._call(funcs, *args, **kwds)
    33853392            elif n == 2:
    3386             # if ther eare two extra args, then pull them out and pass them as a tuple
     3393            # if there are two extra args, then pull them out and pass them as a tuple
    33873394                xmin = args[0]
    33883395                xmax = args[1]
    33893396                args = args[2:]
    class PlotFactory(GraphicPrimitiveFactor 
    34373444        dd = delta
    34383445
    34393446        exceptions = 0; msg=''
     3447        exception_indices = []
    34403448        for i in range(plot_points):
    34413449            xi = xmin + i*delta
    34423450            # Slightly randomize points except for the first and last
    class PlotFactory(GraphicPrimitiveFactor 
    34503458            try:
    34513459                y = f(xi)
    34523460                data[i] = (float (xi), float(y))
    3453             except (ZeroDivisionError, TypeError, ValueError), msg:
    3454                 sage.misc.misc.verbose("%s\nUnable to compute f(%s)"%(msg, x),1)
     3461            except (ZeroDivisionError, TypeError, ValueError,OverflowError), msg:
     3462                sage.misc.misc.verbose("%s\nUnable to compute f(%s)"%(msg, x),1)
    34553463                exceptions += 1
    3456 
     3464                exception_indices.append(i)
     3465        data = [data[i] for i in xrange(len(data)) if i not in exception_indices]
     3466           
    34573467        # adaptive refinement
    34583468        i, j = 0, 0
    34593469        max_bend = float(options['max_bend'])