ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 12 May 2019 15:52:37 -0500Putting label in the right spot (upper-left) during animationhttp://ask.sagemath.org/question/46496/putting-label-in-the-right-spot-upper-left-during-animation/I'm quite new to SageMath. It took some time (half a sunday) to create a code the draws an elliptic curve with a cubic, controlling the speed of the animation and putting a label in. However, I don't know where I can put something like a `legend_loc='upper left` somewhere or whether that's even possible. My code is as follows:
step=0.2;
var('x,y');
a=animate([
plot(EllipticCurve(y^2==x^3+3.8*x^2-0.8*x+float(k)),xmin=-6,xmax=0
,color="red",thickness=2,legend_label=r'$y^2=x^3+3.8x^2-0.8x+{}$'.format(float(k)))
+plot(EllipticCurve(y^2==x^3+3.8*x^2-0.8*x+float(k)),xmin=10^(-9),xmax=6
,color="red",thickness=2)
+ plot(x^3+3.8*x^2-0.8*x+float(k),xmin=-6,xmax=6,color="blue",thickness=1)
for k in srange(-5,5,step)],xmin=-6,xmax=6,ymin=-20,ymax=20,gridlines=[[-6,6],[-20,20]]);
a.show(delay=1)
I also tried `set_legend_options(shadow=False, loc=2)` in the `plot` function, but that doesn't satisfy SageMath either. Anyone an idea how I can put that label at some fixed spot? Btw, it would be even better if I could put that label on the top centre **above** the animation. I appreciate any suggestions and help.AlgebearSun, 12 May 2019 15:52:37 -0500http://ask.sagemath.org/question/46496/Animate 3d surface and add some curves ?http://ask.sagemath.org/question/46284/animate-3d-surface-and-add-some-curves/ I want animate my surface of hyperboloid by adding 2 point then draw a geodesic curve between them .
Thanks for ur help guys Taoufik ahanchaouSat, 20 Apr 2019 01:15:49 -0500http://ask.sagemath.org/question/46284/Animate Bar Graphhttp://ask.sagemath.org/question/24783/animate-bar-graph/In SAGE, is there a way to use the animate command in conjunction with a bar graph?
I can't seem to get it to work. Let's say for argument's sake I want to have a list of N elements and I want to animate reading in each element and sort them by parity then display the output on a bargraph and then animate this through N iterations.
Thank you!sagebarTue, 04 Nov 2014 12:39:58 -0600http://ask.sagemath.org/question/24783/Animation doesn't workhttp://ask.sagemath.org/question/37209/animation-doesnt-work/I'm using a tutorial and should get an animation from this, but nada. All I get is the title: Animation with 20 frames, and nothing else. Is this correct or did the author miss something? I've waited ten minutes and my computer isn't That slow ;) Midrange Acer with four cores. Local server in a virtualbox on win 8. I also tried it in Firefox as well as Chrome. No change.
f(x) = 5*x - x^2/8 + x^3/1200
df(x) = diff(f(x),x)
max = 100
p = plot(f(x),x,0,max)
lblp = text("$y = " + latex(f(x)) + "$",[40,100],fontsize=14)
lbldp = text("$y' = " + latex(df(x)) + "$",[40,80],fontsize=14,rgbcolor='#006000')
ga = []
for argx in srange(0,max,5):
dp = plot(f(argx) + (df(argx)*(x-argx)),x,0,max,color="#006000")
xp = point((argx,f(argx)),rgbcolor='#800000')
ga.append(p+lblp+lbldp+dp+xp)
animate(ga,ymin=0,ymax=max,axes_labels=['x','y'],fontsize=12,figsize=(4,3)).show(delay=1)cybervigilanteThu, 06 Apr 2017 21:26:38 -0500http://ask.sagemath.org/question/37209/How to plot an animated object and one object in same planehttp://ask.sagemath.org/question/33283/how-to-plot-an-animated-object-and-one-object-in-same-plane/ I want to concatenate 2 plots... but I cant
a = animate((line([(0,0), (cos(c), sin(c))]) for c in srange(0,2*pi, pi/4)))
p = circle((0,0), 0.10, fill=true, color='magenta')
c = a+b // I get the error here...
How to do this?
joyceMiracleSun, 01 May 2016 17:27:04 -0500http://ask.sagemath.org/question/33283/Suggestions for improving speedhttp://ask.sagemath.org/question/30974/suggestions-for-improving-speed/ I'm working on visualizing a flow in R^3, and specifically focusing on how the flow behaves near a torus on inner radius 1 and outer radius 2, centered at the origin. The idea is to take a point (x,y,z), and look at this point using coordinates (r,z), in the plane containing (x,y,z) and the origin. Then I take equations in polar coordinates in this plane, and apply them to the point. Moving back into R^3, I take a rotation of the point, and add in the result of the flow restricted to the plane. Most of these conditions also require that I know the minimum distance from (x,y,z) to the torus mentioned.
This is taking a very long time, especially when I try to animate the flow. The last animation I tried took 20 hours, and that was before I found a flaw in the construction. This one works, but I'm hoping to optimize it before I try it again. Any suggestions on how to speed things up would be appreciated.
x,y,u,v = var('x y u v')
ep = 0.1 #step size
length = 350 #iterations
#initial conditions
omega_seeds = [(-1,-1,2),(1,-1,2),(-1,1,2),(1,1,2),(2,2,2),(-2,2,2),(2,-2,2),(-2,-2,2)]
twopi = 2 * RDF.pi()
c(r) = 2/3*(4**(r+1)-4)
def norm2((x,y)):
"""
Norm of `(x,y)`
"""
return float(sqrt((x^2 + y^2)))
def norm3((x,y,z)):
"""
Norm squared of `(x,y,z)`
"""
return x^2 + y^2 + z^2
def norm((x,y,z)):
"""
Norm of `(x,y,z)`
"""
return float(sqrt(norm3((x,y,z))))
def dist((x,y,z),(xx,yy,zz)):
"""
Distance from `(x,y,z)` to `(xx,yy,zz)`
"""
return norm((x - xx, y - yy,z-zz))
def atan2((x,y)): #generalized arctangent
if x == 0 and y < 0:
return 3*pi/2
elif x == 0 and y > 0:
return pi/2
else:
a = float(arctan(abs(y/x)))
if x > 0:
if y > 0:
return a
elif y < 0:
return -a
elif y == 0:
return 0
elif x < 0:
if y > 0:
return pi-a
elif y < 0:
return a-pi
#Functions to determine distances of a point from a specified torus
def Torus_dist((x,y,z),n):
A = vector([0,c(n),0])
if n%2 == 0:
B = vector([x,y,0])
else:
B = vector([0,y,z])
if A == B:
return 4^n
else:
t = (2*4^n)/(norm(A - B))
v = t*B+ (1-t)*A
C = vector([v[0],v[1],v[2]])
if dist(C,(x,y,z)) <= 4^n:
return 0
else:
D = vector([x,y,z])
t2 = 4^n/norm(C-D)
v2 = t2*D + (1-t2)*C
E = vector([v2[0],v2[1],v2[2]])
return dist((x,y,z),E)
def dz(x,y): #vertical component of the flow restricted to the plane
r = norm2((x,y))
if r <=1:
return 0
if r >=2:
return y
theta = atan2((x,y))
dr = cos(theta)*(1-1/r^2)
dtheta = -sin(theta)*(1+1/r^2)
return float(dr*cos(theta)-r*sin(theta)*dtheta)
def dr(x,y): #horizontal component of the flow restricted to the plane
r = norm2((x,y))
if r <=1:
return 0
if r >=2:
return 0
theta = atan2((x,y))
dr = cos(theta)*(1-1/r^2)
dtheta = -sin(theta)*(1+1/r^2)
return float(dr*sin(theta) + r*cos(theta)*dtheta)
def W1((x,y,z)): #dx for the points in R^3
r = 2 - norm2((x,y))
T = max(0,1-Torus_dist((x,y,z),0))
theta = atan2((x,y))
if 0<=z<=2:
return T*y + dr(r,z)*cos(theta)
elif -2<=z<=0:
return (-1)*T*y + dr(r,z)*cos(theta)
else:
return 0
def W2((x,y,z)): #dy for the points in R^3
r = 2 - norm2((x,y))
T = max(0,1-Torus_dist((x,y,z),0))
theta = atan2((x,y))
if 0<=z<=2:
return (-1)*T*x + dr(r,z)*sin(theta)
elif -2<=z<=0:
return T*x + dr(r,z)*sin(theta)
else:
return 0
def W3((x,y,z)): #dz for the points in R^3
r = 2 - norm2((x,y))
if -2<=z<=2:
return -dz(r,z)
else:
return 0
def Plugplot((x,y,z)): #takes a point in R^3 and returns a point epsilon distance away, in the direction of the gradient at that point
n = norm((x - W1((x,y,z)), y - W2((x,y,z)),z-W3((x,y,z))))*(1/ep)
if n == 0:
return ((x,y,z))
else:
return ((x + W1((x,y,z))/n), (y + W2((x,y,z))/n), (z + W3((x,y,z))/n))
def PlugFlow((x,y,z)): #creates a collection of lines through the points generated by Plugplot
L = []
ic = (x,y,z)
if z >= -2:
for i in range(length):
L.append(line((ic,Plugplot(ic)),color='blue'))
ic = Plugplot(ic)
return L
a,b = 2,1 # outer and inner radii
Tx = (a + b*cos(u))*cos(v)
Ty = (a + b*cos(u))*sin(v)
Tz = b*sin(u)
T = parametric_plot3d([Tx,Ty,Tz], (u,0,twopi),(v,0,twopi), opacity=.2,aspect_ratio=1,color='black')
#Adds all of the to an array with the torus T
L = [T]
for i in omega_seeds:
L = L + PlugFlow(i)
show(sum(L) ,frame=true,aspect_ratio=1)jford1906Sun, 22 Nov 2015 16:34:58 -0600http://ask.sagemath.org/question/30974/Update animate.py for gif creation using ffmpeghttp://ask.sagemath.org/question/10463/update-animatepy-for-gif-creation-using-ffmpeg/As I tried to run
Animated plots -- Sage Reference Manual v5.11: 2D Graphics
and there the example
a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
xmin=0, xmax=2*pi, figsize=[2,1])
dir = tmp_dir()
#a.ffmpeg(savefile=dir + 'new.mpg') # optional -- ffmpeg
#a.ffmpeg(savefile=dir + 'new.avi') # optional -- ffmpeg
a.ffmpeg(savefile=dir + 'new.gif') # optional -- ffmpeg
#a.ffmpeg(savefile=dir + 'new.mpg', show_path=True) # optional -- ffmpeg
there appeared an error on the gif creation. Thus using the option verbose = true. There the error was explained to appear in
/Applications/Sage-5.11-OSX-64bit-10.6.app/Contents/Resources/sage/devel/sage-main/build/sage/plot/animate.py
in line 570.
There the line is
ffmpeg_options += ' -pix_fmt rgb24 -loop_output %s ' % iterations
where the option -loop_output should be changed to -loop as I did since ffmpeg states "This option is deprecated, use -loop".
Then the creation of a gif file worked with my version of ffmpeg: 1.2.1, using the ffmpeg command but the file is still of minor quality compared to e.g. mp4.
So perhaps somebody of the staff team can change the animate.py file for future versions. I know that it should be done by a ticket but as a newbee I'm not familiar in making up a ticket. Thanks
jazzThu, 22 Aug 2013 06:15:42 -0500http://ask.sagemath.org/question/10463/My web sagemath stopped all my animation cells. I have tried Mac and PC browsers. All browsers display jmol applet can not load!http://ask.sagemath.org/question/9553/my-web-sagemath-stopped-all-my-animation-cells-i-have-tried-mac-and-pc-browsers-all-browsers-display-jmol-applet-can-not-load/My web sagemath stopped all my animation cells. I have tried Mac and PC browsers. All browsers display jmol applet can not load! I updated Java plugins on my PC and got the 3d images working. However, all my animation cells on my Mac and PC only display a message about the frames.
What is going on. I use Sage for mathematical animation. Someone! Help!squishemTue, 20 Nov 2012 18:59:37 -0600http://ask.sagemath.org/question/9553/Multiple loops in an animation?http://ask.sagemath.org/question/9205/multiple-loops-in-an-animation/I want to use two loops to produce an animation of some gridlines changing gradient.
Essentially making all these lines:
t=var('t')
p1=Graphics()
p2=Graphics()
for i in range(-5,5,1):
p1 +=parametric_plot((t,i),(t,-5,5),color="red")
p2 +=parametric_plot((i,t),(t,-5,5),color="blue")
show(p1+p2)
Move like these lines all at once:
t=var('t')
p1=Graphics()
p2=Graphics()
v = []
for a in srange(-5,5,1):
p1 =parametric_plot((t,t*a),(t,-5,5),color="red")
p2 =parametric_plot((t*a,t),(t,-5,5),color="blue")
v.append(p1+p2)
j = animate (v, xmin=-2,ymin=-2,xmax=2,ymax=2,figsize=[2,2])
j.show()
How can I combine these two into one animation? Insaneg33kSat, 04 Aug 2012 05:53:38 -0500http://ask.sagemath.org/question/9205/Making an array of animationshttp://ask.sagemath.org/question/9156/making-an-array-of-animations/I'm making a simple demo of the relationship between the unit circle and the sine function, like the one at http://treeblurb.com/dev_math/sin_canv00.html. I would like to plot the circle and function side by side, but graphics_array gives an error, saying that all its elements must be graphics. Is there anything I can do?
Here's the code as it now stands.
singraph=animate([point((i,sin(i)), color="green", size=50) + plot(sin(x),(0,2*pi)) for i in srange(0,2*pi,0.2)], xmin=0, xmax=7, ymin=-1, ymax=1, figsize=[2,2])
unitcircle = animate([point((cos(i),sin(i)), color="green", size=50) + circle((0,0),1, color="blue") for i in srange(0,2*pi,0.2)], figsize=[2,2])
singraph.show()
unitcircle.show()jaiaSat, 14 Jul 2012 14:37:22 -0500http://ask.sagemath.org/question/9156/Animated spherehttp://ask.sagemath.org/question/8993/animated-sphere/I plotted an union of parametric curves in 3D (like a rollercoaster) and I want to create a solid sphere (radius of 0.5 approx.) that moves along the whole curve. You can do this in sage?AlbertsssTue, 22 May 2012 05:45:30 -0500http://ask.sagemath.org/question/8993/