Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33264: add "x = SR.var('x')" to several animation examples.
Browse files Browse the repository at this point in the history
The (absence of the) implicitly defined "x" often causes new users
some confusion in code that uses "x" for another purpose. Here we make
the definition explicit within the examples for sage.plot.animate.py.
  • Loading branch information
orlitzky committed Feb 3, 2022
1 parent 439907f commit e73cd12
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/sage/plot/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
The sine function::
sage: x = SR.var("x")
sage: sines = [plot(c*sin(x), (-2*pi,2*pi), color=Color(c,0,0), ymin=-1, ymax=1) for c in sxrange(0,1,.2)]
sage: a = animate(sines)
sage: a # optional -- ImageMagick
Expand Down Expand Up @@ -61,8 +62,7 @@
Animations of 3d objects::
sage: var('s,t')
(s, t)
sage: s,t = SR.var("s,t")
sage: def sphere_and_plane(x):
....: return sphere((0,0,0),1,color='red',opacity=.5)+parametric_plot3d([t,x,s],(s,-1,1),(t,-1,1),color='green',opacity=.7)
sage: sp = animate([sphere_and_plane(x) for x in sxrange(-1,1,.3)])
Expand All @@ -72,7 +72,7 @@
Graphics3d Object
sage: sp.show() # optional -- ImageMagick
sage: (x,y,z) = var('x,y,z')
sage: (x,y,z) = SR.var("x,y,z")
sage: def frame(t):
....: return implicit_plot3d((x^2 + y^2 + z^2), (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=60, contour=[1,3,5], region=lambda x,y,z: x<=t or y>=t or z<=t)
sage: a = animate([frame(t) for t in srange(.01,1.5,.2)])
Expand All @@ -85,7 +85,7 @@
method :meth:`sage.plot.animate.Animation.make_image`. This is
illustrated by the following example::
sage: t = var('t')
sage: t = SR.var("t")
sage: a = animate((sin(c*pi*t) for c in sxrange(1,2,.2)))
sage: a.show() # optional -- ImageMagick
Expand Down Expand Up @@ -133,7 +133,7 @@ def animate(frames, **kwds):
EXAMPLES::
sage: t = var('t')
sage: t = SR.var("t")
sage: a = animate((cos(c*pi*t) for c in sxrange(1,2,.2)))
sage: a.show() # optional -- ImageMagick
Expand Down Expand Up @@ -161,6 +161,7 @@ class Animation(WithEqualityById, SageObject):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.3)],
....: xmin=0, xmax=2*pi, figsize=[2,1])
sage: a # optional -- ImageMagick
Expand Down Expand Up @@ -200,13 +201,15 @@ class Animation(WithEqualityById, SageObject):
We check that :trac:`7981` is fixed::
sage: x = SR.var("x")
sage: a = animate([plot(sin(x + float(k)), (0, 2*pi), ymin=-5, ymax=5)
....: for k in srange(0,2*pi,0.3)])
sage: a.show() # optional -- ImageMagick
Do not convert input iterator to a list, but ensure that
the frame count is known after rendering the frames::
sage: x = SR.var("x")
sage: a = animate((plot(x^p, (x,0,2)) for p in sxrange(1,2,.1)))
sage: str(a)
'Animation with unknown number of frames'
Expand All @@ -229,6 +232,7 @@ def __init__(self, v=None, **kwds):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.3)],
....: xmin=0, xmax=2*pi, figsize=[2,1]) # indirect doctest
sage: a # optional -- ImageMagick
Expand Down Expand Up @@ -404,7 +408,7 @@ def make_image(self, frame, filename, **kwds):
....: P = parametric_plot(frame[0], frame[1], **frame[2])
....: P.save_image(filename,**kwds)
sage: t = var('t')
sage: t = SR.var("t")
sage: x = lambda t: cos(t)
sage: y = lambda n,t: sin(t)/n
sage: B = MyAnimation([([x(t), y(i+1,t)],(t,0,1), {'color':Color((1,0,i/4)), 'aspect_ratio':1, 'ymax':1}) for i in range(4)])
Expand Down Expand Up @@ -451,6 +455,7 @@ def png(self, dir=None):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([plot(x^2 + n) for n in range(4)], ymin=0, ymax=4)
sage: d = a.png(); v = os.listdir(d); v.sort(); v # long time
['00000000.png', '00000001.png', '00000002.png', '00000003.png']
Expand Down Expand Up @@ -507,7 +512,7 @@ def graphics_array(self, ncols=3):
Frames can be specified as a generator too; it is internally converted to a list::
sage: t = var('t')
sage: t = SR.var("t")
sage: b = animate((plot(sin(c*pi*t)) for c in sxrange(1,2,.2)))
sage: g = b.graphics_array()
sage: g
Expand Down Expand Up @@ -557,6 +562,7 @@ def gif(self, delay=20, savefile=None, iterations=0, show_path=False,
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1])
sage: td = tmp_dir()
Expand Down Expand Up @@ -633,6 +639,7 @@ def _gif_from_imagemagick(self, savefile=None, show_path=False,
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1])
sage: td = tmp_dir()
Expand Down Expand Up @@ -692,6 +699,7 @@ def _rich_repr_(self, display_manager, **kwds):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([plot(x^2 + n) for n in range(4)], ymin=0, ymax=4)
sage: from sage.repl.rich_output import get_display_manager
sage: dm = get_display_manager()
Expand Down Expand Up @@ -784,6 +792,7 @@ def show(self, delay=None, iterations=None, **kwds):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, figsize=[2,1])
sage: a.show() # optional -- ImageMagick
Expand Down Expand Up @@ -896,6 +905,7 @@ def ffmpeg(self, savefile=None, show_path=False, output_format=None,
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1])
sage: td = tmp_dir()
Expand Down Expand Up @@ -1012,6 +1022,7 @@ def apng(self, savefile=None, show_path=False, delay=20, iterations=0):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, figsize=[2,1])
sage: dir = tmp_dir()
Expand Down Expand Up @@ -1073,6 +1084,7 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds):
EXAMPLES::
sage: x = SR.var("x")
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1])
sage: td = tmp_dir()
Expand Down Expand Up @@ -1151,6 +1163,7 @@ def interactive(self, **kwds):
EXAMPLES::
sage: x = SR.var("x")
sage: frames = [point3d((sin(x), cos(x), x)) for x in (0, pi/16, .., 2*pi)]
sage: animate(frames).interactive(online=True)
Graphics3d Object
Expand Down Expand Up @@ -1216,6 +1229,7 @@ class APngAssembler(object):
EXAMPLES::
sage: from sage.plot.animate import APngAssembler
sage: x = SR.var("x")
sage: def assembleAPNG():
....: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
....: xmin=0, xmax=2*pi, figsize=[2,1])
Expand Down

0 comments on commit e73cd12

Please sign in to comment.