Ticket #2517: plot_undefined.2.patch

File plot_undefined.2.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 1205876738 18000
    # Node ID 5dc8d1bb9688df19de25300e487e9a0d3db9a10a
    # Parent  30d3b4bf91bef7463b5ec55393b66402bcb6298b
    Delete undefined values from the plot.
    
    diff -r 30d3b4bf91be -r 5dc8d1bb9688 sage/plot/plot.py
    a b class PlotFactory(GraphicPrimitiveFactor 
    34713471        sage: plot([sin(n*x) for n in [1..4]], (0, pi))
    34723472
    34733473
    3474     The function $\sin(1/x)$ wiggles wildtly near $0$, so the
     3474    The function $\sin(1/x)$ wiggles wildly near $0$, so the
    34753475    first plot below won't look perfect.  Sage adapts to this
    34763476    and plots extra points near the origin.
    34773477        sage: plot(sin(1/x), (x, -1, 1))
    class PlotFactory(GraphicPrimitiveFactor 
    35023502    We can change the line style to one of '--' (dashed), '-.' (dash dot),
    35033503    '-' (solid), 'steps', ':' (dotted):
    35043504        sage: plot(sin(x), 0, 10, linestyle='-.')
     3505
     3506    Sage currently ignores points that cannot be evaluated
     3507        sage: plot(-x*log(x), (x,0,1))
     3508        sage: plot(x^(1/3), (x,-1,1))
     3509
     3510    To plot the negative real cube root, use something like the following.
     3511        sage: plot(lambda x : RR(x).nth_root(3), (x,-1, 1) )
    35053512
    35063513    TESTS:
    35073514    We do not randomize the endpoints:
    class PlotFactory(GraphicPrimitiveFactor 
    35463553            elif n == 1:
    35473554                G = self._call(funcs, *args, **kwds)
    35483555            elif n == 2:
    3549             # if ther eare two extra args, then pull them out and pass them as a tuple
     3556            # if there are two extra args, then pull them out and pass them as a tuple
    35503557                xmin = args[0]
    35513558                xmax = args[1]
    35523559                args = args[2:]
    class PlotFactory(GraphicPrimitiveFactor 
    36003607        dd = delta
    36013608
    36023609        exceptions = 0; msg=''
     3610        exception_indices = []
    36033611        for i in range(plot_points):
    36043612            xi = xmin + i*delta
    36053613            # Slightly randomize the interior sample points if
    class PlotFactory(GraphicPrimitiveFactor 
    36133621                xi = xmax  # guarantee that we get the last point.
    36143622               
    36153623            try:
    3616                 y = f(xi)
    3617                 data[i] = (float (xi), float(y))
    3618             except (ZeroDivisionError, TypeError, ValueError), msg:
     3624                data[i] = (float(xi), float(f(xi)))
     3625            except (ZeroDivisionError, TypeError, ValueError,OverflowError), msg:
    36193626                sage.misc.misc.verbose("%s\nUnable to compute f(%s)"%(msg, x),1)
    36203627                exceptions += 1
    3621 
     3628                exception_indices.append(i)
     3629        data = [data[i] for i in range(len(data)) if i not in exception_indices]
     3630           
    36223631        # adaptive refinement
    36233632        i, j = 0, 0
    36243633        max_bend = float(options['max_bend'])