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

animate ignores options to show that are passed up from the plot command #7981

Closed
jasongrout opened this issue Jan 18, 2010 · 35 comments
Closed

Comments

@jasongrout
Copy link
Member

This animate command shouldn't ignore the options to show() that are passed through by the plot command (here the options are ymin and ymax):

sage: var('t')
sage: damped_oscillator = 41/311*sqrt(311)*e^(-3/8*t)*sin(1/8*sqrt(311)*t) + 3*e^(-3/8*t)*cos(1/8*sqrt(311)*t)
sage: animate([plot( lambda x: damped_oscillator( t = x + k ), -1/2, 3*pi, ymin=-2, ymax=3.5 ) for k in srange( 0, pi, 0.3 ) ]).show()

Thanks to Johann Myrkraverk Oskarsson for reporting this.

CC: @sagetrac-wcauchois

Component: graphics

Author: Jason Grout, Andrey Novoseltsev

Reviewer: Tim Dumol, Marshall Hampton, Karl-Dieter Crisman

Merged: sage-4.6.2.alpha2

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

@jasongrout
Copy link
Member Author

comment:1

Attachment: trac-7981-show_options.patch.gz

@jasongrout
Copy link
Member Author

Author: Jason Grout

@jasongrout
Copy link
Member Author

comment:4

Bill and Karl-Dieter,

You two might be interested in this. Karl-Dieter, you wrote the original code that passed show options around, I believe. I just made the consolidation happen in .save() instead of .show().

@jasongrout
Copy link
Member Author

comment:5

This fixes #7524.

@kcrisman
Copy link
Member

comment:6

Umm... I find that unlikely, though I may have broken something inadvertently.

@TimDumol
Copy link
Mannequin

TimDumol mannequin commented Jan 20, 2010

comment:7

Doctesting on plot.py results in 2 errors:

{{[
sage -t "devel/sage-ref/sage/plot/plot.py"
--leak-resolution=high --log-socket=127.0.0.1 --leak-check=full --num-callers=25 --suppressions=/opt/sage-4.3.rc0.O0/local/lib/valgrind/sage.supp


File "/home/timdumol/sage-4.3.1.alpha0/devel/sage-ref/sage/plot/plot.py", line 1925:
sage: c.show(figsize=[5,5], xmin=-1, xmax=3, ymin=-1, ymax=3) sage: point((-1,1),pointsize=30, color='red')
Exception raised:
Traceback (most recent call last):
File "/home/timdumol/sage-4.3.1.alpha0/local/bin/ncadoctest.py", line 1231, in run_one_test
self.run_one_example(test, example, filename, compileflags)
File "/home/timdumol/sage-4.3.1.alpha0/local/bin/sagedoctest.py", line 38, in run_one_example
OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
File "/home/timdumol/sage-4.3.1.alpha0/local/bin/ncadoctest.py", line 1172, in run_one_example
compileflags, 1) in test.globs
File "<doctest main.example_37[5]>", line 1
c.show(figsize=[Integer(5),Integer(5)], xmin=-Integer(1), xmax=Integer(3), ymin=-Integer(1), ymax=Integer(3)) sage: point((-Integer(1),Integer(1)),pointsize=Integer(30), color='red')###line 1925:
sage: c.show(figsize=[5,5], xmin=-1, xmax=3, ymin=-1, ymax=3) sage: point((-1,1),pointsize=30, color='red')
^
SyntaxError: invalid syntax


File "/home/timdumol/sage-4.3.1.alpha0/devel/sage-ref/sage/plot/plot.py", line 1930:
sage: c.save(DOCTEST_MODE_FILE)
Exception raised:
Traceback (most recent call last):
File "/home/timdumol/sage-4.3.1.alpha0/local/bin/ncadoctest.py", line 1231, in run_one_test
self.run_one_example(test, example, filename, compileflags)
File "/home/timdumol/sage-4.3.1.alpha0/local/bin/sagedoctest.py", line 38, in run_one_example
OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
File "/home/timdumol/sage-4.3.1.alpha0/local/bin/ncadoctest.py", line 1172, in run_one_example
compileflags, 1) in test.globs
File "<doctest main.example_37[7]>", line 1, in
c.save(DOCTEST_MODE_FILE)###line 1930:
sage: c.save(DOCTEST_MODE_FILE)
NameError: name 'DOCTEST_MODE_FILE' is not defined


1 items had failures:
2 of 8 in main.example_37
}}}

@TimDumol
Copy link
Mannequin

TimDumol mannequin commented Jan 20, 2010

Reviewer: Tim Dumol

@TimDumol TimDumol mannequin added s: needs work and removed s: needs review labels Jan 20, 2010
@jasongrout
Copy link
Member Author

comment:8

Here is another effect of this, I think:

plot(x,(x,0,1),aspect_ratio=1).save('test.png')

does not save a graph with aspect ratio 1.

@novoselt
Copy link
Member

Changed author from Jason Grout to Jason Grout, Andrey Novoseltsev

@novoselt
Copy link
Member

comment:9

I have just wrote a patch fixing the issue for save (which is quite annoying in conjunction with SageTeX) and then found this ticket. Since the original patch does not apply cleanly on sage-4.6.alpha1, I posted my patch, but I have incorporated Jason's changes to show to eliminate double processing of options.

I have changed call parameters to save since it is not documented why one would ever need savenow=False. If I want to save later, shouldn't I call save later?-) Also it does not make sense in my opinion to use any extra positional arguments in this function except for the file name. I realize that this is a backward-incompatible change, but all long tests pass with this patch.

@novoselt
Copy link
Member

comment:10

Made it possible to apply the new patch after #10291 (which is now positively reviewed).

@novoselt
Copy link
Member

novoselt commented Dec 5, 2010

comment:11

For the buildbot

Apply trac-7981-save_ignores_preset_plotting_options.patch

@novoselt novoselt assigned novoselt and unassigned williamstein Dec 5, 2010
@sagetrac-mhampton
Copy link
Mannequin

sagetrac-mhampton mannequin commented Jan 12, 2011

Changed reviewer from Tim Dumol to Tim Dumol, Marshall Hampton

@sagetrac-mhampton
Copy link
Mannequin

sagetrac-mhampton mannequin commented Jan 12, 2011

comment:12

This seems to work, and all doctests in the module plot (not just the file) pass.

Sadly it didn't also fix #10244, so I will try to figure that out if I can.

Positive review.

@kcrisman
Copy link
Member

comment:13

Just out of curiosity, what is the 'backward-incompatible' change you mention? Which extra positional arguments - like dpi? (Though Jason also got rid of that - I wonder why?)

I guess I mean to ask whether this is a good such change; usually there is a deprecation period. After all, doctests catch very few of our use cases :) What is wrong with the usual *args,**kwds syntax?

As for savenow, it looks like with it being False we could still create a Sage object. You are right that it seems a little redundant, though!

Also, this needs a doctest (it's in the original patch) to show that animate options actually work, at least in theory (if one looked at it and ran the optional tests). So... needs work. Sorry :(

@kcrisman
Copy link
Member

Changed reviewer from Tim Dumol, Marshall Hampton to Tim Dumol, Marshall Hampton, Karl-Dieter Crisman

@kcrisman
Copy link
Member

reviewer patch

@kcrisman
Copy link
Member

comment:21

Attachment: trac_7981-reviewer.patch.gz

Just an update - apparently

sage: animate([plot(sin(x + float(k)), (0, 2*pi), ymin=-5, ymax=5)
...            for k in srange(0,2*pi,0.3)]).show() # optional

does not obey the optional test, for it created a new file (I must have ImageMagick!). We don't create non-temp new files in doctests, though, so this had to be changed. New reviewer patch fixes this as well, maintains positive review. Should not affect the plot patches which depend on this.

@jdemeyer
Copy link

comment:22

Maybe you should document in the file what you just said in your comment. Also make it clear why the test is tagged optional.

@kcrisman
Copy link
Member

comment:23

Hmm, but in many places in this file it says why such things are optional. In fact, earlier in the same docstring the first occurrence of .show() explains this:

        sage: a.show()          # optional -- requires convert command

as well as several lines later

        sage: a.show() # optional -- requires convert command

so hopefully one wouldn't need to do it a third time in three paragraphs. Especially since it's a TEST.

Also, the actual issue with creating a file I have posted to sage-devel about; it's not 100% clear to me that this is a bug. It just happened to have a bad effect here, which I changed from Andrey's patch. But it's orthogonal to the ticket.

So putting back to 'needs review'. I hope you will agree with me that this is in fact still worthy of positive review.

Now, of course there is in the doctesting framework the issue that one can do optional tests with only certain keywords, so if one has convert one could run them with that keyword. But in that case, the entire file animate.py is replete with violations of this, and I feel that should be a separate ticket.

@jdemeyer
Copy link

comment:24

Replying to @kcrisman:

Hmm, but in many places in this file it says why such things are optional. In fact, earlier in the same docstring the first occurrence of .show() explains this:

        sage: a.show()          # optional -- requires convert command

as well as several lines later

        sage: a.show() # optional -- requires convert command

so hopefully one wouldn't need to do it a third time in three paragraphs. Especially since it's a TEST.

Personally, I would write it a third time. On the other hand, I don't care too much. So if you feel like you're happy with the patch as-is, then that's fine for me.

@kcrisman
Copy link
Member

comment:25

so hopefully one wouldn't need to do it a third time in three paragraphs. Especially since it's a TEST.

Personally, I would write it a third time. On the other hand, I don't care too much. So if you feel like you're happy with the patch as-is, then that's fine for me.

Yes, I am. This issue is pretty important, and the other issue is somewhat orthogonal. I've opened another ticket for the issue about the optional keyword - this is now #10655.

@kcrisman
Copy link
Member

comment:26

'This issue' meaning this ticket itself, of course :-)

@jdemeyer
Copy link

comment:27

Please specify which patches have to be applied.

@novoselt
Copy link
Member

comment:28

Please apply trac-7981-save_ignores_preset_plotting_options.patch and trac_7981-reviewer.patch

@kcrisman
Copy link
Member

comment:30

Replying to @jdemeyer:

Please specify which patches have to be applied.

Just FYI, this was already noted in comment 19.

@jdemeyer
Copy link

Merged: sage-4.6.2.alpha2

@fchapoton

This comment has been minimized.

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

6 participants