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
Automatic exclusion of non-domain points in things like arcsec #13246
Comments
arcsec plot |
comment:1
Attachment: tmp_1.png Here is what the bad plot looks like. This function should not be defined in the middle. |
comment:2
Hey ppurka, I know you like a challenge and know the plotting code pretty well... :) |
comment:3
Replying to @kcrisman:
Hehe, I will have a look. :) This problem had come up in sage-support or sage-devel too a couple of months back. |
comment:4
Here's an idea I thought of that would help avoid these ugly situations. The problem is that we build our plot out of lots of tiny line segments, and we have a line segment connecting things that it should not connect. So: Let Since going through the list would be expensive and rarely needed, we would only do this with a keyword, say Does that seem reasonable? That would fix the original problem at the cost of a little speed. |
comment:5
@dandrake: I guess the point of this ticket is to make the exclusion automatic. Surely, there will be a slowdown if we do this automatically for every plot; the question is what will be the magnitude of the slowdown. I suspect there won't be much slowdown with the default Your solution also sounds plausible. In case we do adopt your solution, I would like it to be a part of the |
comment:6
Hmm, this idea is not bad. Particularly since we pick a default step size for the |
comment:7
Can you check many different plots with and without this patch? It should fix two things:
|
comment:8
Hold on.. this patch is not right. It has broken at least two plots:
The first one I can understand, but I don't understand the problem with the second one. Edit: Can't reproduce this. See comment:10. |
comment:9
My totally gut guess is that you're not taking adaptive recursion into account enough. Of course, one would think that would make the distance between plot points even smaller, but who knows? I'd insert a print statement in your while loop to see what's being excluded. Also, does |
comment:10
Actually, I am trying to reproduce it on my laptop now, and I can't reproduce the failures. I don't know what happened back then. I was manually going through each plot command in the docstrings and plotting it and verifying visually whether it was all right. For both the above examples I was getting a straight horizontal line. Now, when I am plotting it again, I don't see any anomalies. :/ I will let this patch bake for a couple more days, before I set it up for |
comment:11
I manually and visually (!) tested all the plots in the doctests of Setting this up for review. If you know a bunch of ill-behaving functions like |
This comment has been minimized.
This comment has been minimized.
comment:13
Please fill in your real name as Author. |
Author: Punarbasu Purkayastha |
Work Issues: fix doctests |
Attachment: trac_13246-automatic-exclusion.patch.gz apply to devel/sage |
Changed work issues from fix doctests to none |
comment:17
Notice this (unsurprisingly) needs a slight rebase. Impressively, this also seems to work correctly with things like
although
would cause an error always - something that probably should be fixed, perhaps this is a good place to do so? Note that there is no helpful error message like with
I'm trying to rack my brain thinking of where
doesn't seem to trigger additional exclusions. Do you see what I mean? One could imagine that in a parametric context there could be a very narrow parameter range, but a lot of room on the x-values and so everything would be excluded. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:58
I think I have fixed the problem with the parametric and polar plots. Needs review. :) |
comment:59
Thank you for all your very hard work on this! |
comment:60
Replying to @kcrisman:
Thanks for your extensive testing! You have uncovered many bugs in this ticket :-) |
comment:61
I get
|
comment:63
hmm.. git is not merging the two tickets correctly. I will have to check. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:65
@vbraun: this should fix the doctest error. This ticket by itself was working fine. Applying this after #16439 introduced a Edit: I think it is because of this git commit in #16439 (that is not merged into this ticket) that a |
comment:66
breaks plot in this case:
|
comment:67
False alarm! It is working as intended.
|
comment:68
I was happy with this, so I guess if Volker can test if the doctest error he saw is gone then we are okay. |
Changed branch from u/ppurka/automatic_exclusion_of_non_domain_points_in_things_like_arcsec to |
From an email exchange about plotting arcsec, slightly out of order:
The immediate context for this issue is a couple of problems that include, among other things, graphing arcsec and its derivative (in one case), arcsec and arccsc (in the other). Since the range of intended functions is known, it appears that this would work if the students follow instructions (big if). But more generally, we want students to have total control over their "graphing calculator" -- at least over the input boxes we provide -- so there's nothing stopping them from entering arcsec(x/2) or something else that we can't anticipate.
The underlying problem is that the plotting code ignores everything
between -1 and 1 (since those values aren't real), but then simply
connects (-1,3) and (1,.2) (or so) with a line segment when it's done. I
have a couple ideas for fixing this, but they won't help you in the near
term.
One workaround for your
@
interact would be to select an option forexclude based on the function: I'm thinking of something like this:
@
interactdef foo(fn=textbox(), ....):
setup stuff...
The idea is just to look at the function being plotted and set a list of
points to exclude based on that. It would be tedious to code, but would
work.
I think that fixing this is possible. I spent about a half hour looking at http://hg.sagemath.org/sage-main/file/9ab4ab6e12d0/sage/plot/plot.py just now and I am pretty sure that one could extract bad points like nan in generate_plot_points. Currently we just do
data = [data[i] for i in range(len(data)) if i not in exception_indices]
which means we completely ignore them, but presumably we could keep this data somehow and return it as part of generate_plot_points (not sure whether that would have to be deprecated) so that we could add that somehow to the exclude data around http://hg.sagemath.org/sage-main/file/9ab4ab6e12d0/sage/plot/plot.py#l1279
The problem is that there could be a lot of these, and that could slow things down a lot to check all of them, but checking for a "consecutive series" would also take some time.
Anyway, it's at least doable in principle, but would take some time and care to implement, making sure it didn't cause any other regressions.
Apply to devel/sage:
Depends on #16439
CC: @dandrake @ppurka @jondo @vbraun
Component: graphics
Author: Punarbasu Purkayastha
Branch/Commit:
384b5a2
Reviewer: Ralf Stephan, Karl-Dieter Crisman
Issue created by migration from https://trac.sagemath.org/ticket/13246
The text was updated successfully, but these errors were encountered: