# 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 |
3471 | 3471 | sage: plot([sin(n*x) for n in [1..4]], (0, pi)) |
3472 | 3472 | |
3473 | 3473 | |
3474 | | The function $\sin(1/x)$ wiggles wildtly near $0$, so the |
| 3474 | The function $\sin(1/x)$ wiggles wildly near $0$, so the |
3475 | 3475 | first plot below won't look perfect. Sage adapts to this |
3476 | 3476 | and plots extra points near the origin. |
3477 | 3477 | sage: plot(sin(1/x), (x, -1, 1)) |
… |
… |
class PlotFactory(GraphicPrimitiveFactor |
3502 | 3502 | We can change the line style to one of '--' (dashed), '-.' (dash dot), |
3503 | 3503 | '-' (solid), 'steps', ':' (dotted): |
3504 | 3504 | 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) ) |
3505 | 3512 | |
3506 | 3513 | TESTS: |
3507 | 3514 | We do not randomize the endpoints: |
… |
… |
class PlotFactory(GraphicPrimitiveFactor |
3546 | 3553 | elif n == 1: |
3547 | 3554 | G = self._call(funcs, *args, **kwds) |
3548 | 3555 | 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 |
3550 | 3557 | xmin = args[0] |
3551 | 3558 | xmax = args[1] |
3552 | 3559 | args = args[2:] |
… |
… |
class PlotFactory(GraphicPrimitiveFactor |
3600 | 3607 | dd = delta |
3601 | 3608 | |
3602 | 3609 | exceptions = 0; msg='' |
| 3610 | exception_indices = [] |
3603 | 3611 | for i in range(plot_points): |
3604 | 3612 | xi = xmin + i*delta |
3605 | 3613 | # Slightly randomize the interior sample points if |
… |
… |
class PlotFactory(GraphicPrimitiveFactor |
3613 | 3621 | xi = xmax # guarantee that we get the last point. |
3614 | 3622 | |
3615 | 3623 | 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: |
3619 | 3626 | sage.misc.misc.verbose("%s\nUnable to compute f(%s)"%(msg, x),1) |
3620 | 3627 | 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 | |
3622 | 3631 | # adaptive refinement |
3623 | 3632 | i, j = 0, 0 |
3624 | 3633 | max_bend = float(options['max_bend']) |