Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore bad values in plot #2517

Closed
jasongrout opened this issue Mar 14, 2008 · 10 comments
Closed

ignore bad values in plot #2517

jasongrout opened this issue Mar 14, 2008 · 10 comments

Comments

@jasongrout
Copy link
Member

> >  Hi,
> >
> >  With sage-2.10.3 the following plot fails:
> >
> >  plot(-x*log(x),0,1, plot_points=1000)
> >
> >  This worked fine in sage-2.10.2. Note that the left hand limit is
> >  well-defined and can be approximated:
> >
> >  plot(-x*log(x),0.00000000000000001,1, plot_points=1000)
> >
> >  Is this a feature or a bug?

It fails because it used to be that there was a bug where when
plotting the left and right endpoints were omitted, because the sample
points were *all* randomized!  This really
annoyed a lot of people, especially people making animations,
but allowed the above example to work.

I think the solution is to fix our plotting code so that it just automatically
completely ignores a few bad values (like it used to), possibly printing
a warning.

 -- William

Component: graphics

Issue created by migration from https://trac.sagemath.org/ticket/2517

@robertwb
Copy link
Contributor

comment:1

We should possible plot the endpoints and randomized values just inside the endpoints for cases like this.

@jasongrout
Copy link
Member Author

comment:2

The patch above takes care of two things:

  • ignores points that have OverflowError when evaluated
  • deletes erroneous points from the plot, thereby solving the longstanding bug of "float not subscriptable" mentioned lots of times previously, for example, when plotting x^(1/3).

@williamstein
Copy link
Contributor

comment:3

I think this line in the patch

print i, data[i], i+1, data[i+1] 

was for debugging purposes and should be deleted.

@jasongrout
Copy link
Member Author

Attachment: plot_undefined.patch.gz

@jasongrout
Copy link
Member Author

comment:4

Sorry, I thought I uploaded a new patch before anyone saw :). The current patch does not have that line.

@williamstein
Copy link
Contributor

comment:5

I applied your patch and it doesn't work. The example above failes with <type 'exceptions.TypeError'>: 'tuple' object is not callable:


sage:  plot(-x*log(x),0,1, plot_points=1000)
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/Users/was/papers/current/modabvar/<ipython console> in <module>()

/Users/was/build/sage-2.10.3.rc3/local/lib/python2.5/site-packages/sage/plot/plot.py in __call__(self, funcs, *args, **kwds)
   3380             del kwds['show']
   3381         if hasattr(funcs, 'plot'):
-> 3382             G = funcs.plot(*args, **kwds)
   3383         # if we are using the generic plotting method
   3384         else:

/Users/was/build/sage-2.10.3.rc3/local/lib/python2.5/site-packages/sage/calculus/calculus.py in plot(self, *args, **kwds)
    913         else:
    914             f = self.function(param)
--> 915         return plot(f, *args, **kwds)
    916 
    917     def __lt__(self, right):

/Users/was/build/sage-2.10.3.rc3/local/lib/python2.5/site-packages/sage/plot/plot.py in __call__(self, funcs, *args, **kwds)
   3380             del kwds['show']
   3381         if hasattr(funcs, 'plot'):
-> 3382             G = funcs.plot(*args, **kwds)
   3383         # if we are using the generic plotting method
   3384         else:

/Users/was/build/sage-2.10.3.rc3/local/lib/python2.5/site-packages/sage/calculus/calculus.py in plot(self, *args, **kwds)
    913         else:
    914             f = self.function(param)
--> 915         return plot(f, *args, **kwds)
    916 
    917     def __lt__(self, right):

/Users/was/build/sage-2.10.3.rc3/local/lib/python2.5/site-packages/sage/plot/plot.py in __call__(self, funcs, *args, **kwds)
   3395                 xmax = args[1]
   3396                 args = args[2:]
-> 3397                 G = self._call(funcs, (xmin, xmax), *args, **kwds)
   3398             else:
   3399                 print "there were %s extra arguments (besides %s)" % (n, funcs)

/Users/was/build/sage-2.10.3.rc3/local/lib/python2.5/site-packages/sage/plot/plot.py in _call(self, funcs, xrange, parametric, polar, label, **kwds)
   3463                 exceptions += 1
   3464                 exception_indices.append(i)
-> 3465         data = [data[i] for i in xrange(len(data)) if i not in exception_indices]
   3466             
   3467         # adaptive refinement

<type 'exceptions.TypeError'>: 'tuple' object is not callable

@williamstein williamstein changed the title ignore bad values in plot [negative review] ignore bad values in plot Mar 15, 2008
@jasongrout
Copy link
Member Author

comment:7

Apply the second patch instead of the first.

Second patch is rebased against 2.10.4 and works correctly.

@jasongrout jasongrout changed the title [negative review] ignore bad values in plot ignore bad values in plot Mar 18, 2008
@jasongrout
Copy link
Member Author

Attachment: plot_undefined.2.patch.gz

@jasongrout jasongrout modified the milestones: sage-3.0, sage-2.11 Mar 18, 2008
@mwhansen
Copy link
Contributor

comment:9

Looks good to me.

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Mar 19, 2008

comment:10

Merged plot_undefined.2.patch in Sage 2.11.alpha0

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Mar 19, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants