ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 18 Jun 2021 19:50:09 +0200How to zoom in on saved plot?https://ask.sagemath.org/question/57620/how-to-zoom-in-on-saved-plot/Hello all!
I'm trying to make some animations for a class I'm teaching, but, while I've been able to have them animate the way I want, when I save the animation the objects are really small compared to the size of the file. For example, this is what one frame of the output looks like: imgur.com/a/BURrSXI; but I'd rather have it look like this: imgur.com/a/l3TVDGK. Is there any way I can control the output of Sage so that the objects take up more of the animation/image? Thank you!
Edit:
If it helps, I am making my animations with parametric_plot3d and Sphere's. I have a graphics object G that I am adding all of my spheres and parametric plots to. Then, I'm saving that graphics object via the .save method.
num_frames_graph = 100
frames_list_graph = [0]*10
frames_list_graph.extend(list(range(0,num_frames_graph)))
frames_list_graph.extend([num_frames_graph for i in range(0,15)])
frames_list_graph.extend(frames_list_graph[::-1])
graph_frames = [graph_projection(RDF(time / num_frames_graph)) for time in frames_list_graph]
os.system("mkdir graphFrames")
for i,frame in enumerate(graph_frames):
frame.save(filename="graphFrames/graph%04d.png"%i,
figsize=[12,8],
dpi = 1000,
xmin = -2.1,
xmax = 2.1,
ymin = -2.1,
ymax = 2.1,
zmin=-2.1,
zmax=2.1,
transparent=True,
aspect_ratio=1
)
os.system('cd graphFrames; convert -delay %s -loop %s *.png "graph.gif"'%(float(100/60),int(0)))
Is the general method of how I'm constructing my animationsddxtanxFri, 18 Jun 2021 19:50:09 +0200https://ask.sagemath.org/question/57620/Problem : ImageMagick and animatehttps://ask.sagemath.org/question/41082/problem-imagemagick-and-animate/Hi,
I have Sage 8.1 and ImageMagick (installed from 7.0.7-22-Q16-x64-dll.exe) installed on W10.
When I execute in Sage Notebook :
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)]
a = animate(sines)
a.show()
I get this :
convert.exe: unable to open image
'/dot_sage/temp/my_desktop/17724/tmp_bfv0BC.gif': No such file or
directory @ error/blob.c/OpenBlob/3335.
Animation with 5 frames
And I have no animation.
How can I solve this ?
Thank youkrokoMon, 12 Feb 2018 23:44:56 +0100https://ask.sagemath.org/question/41082/Where are stored gif files by defaulthttps://ask.sagemath.org/question/36418/where-are-stored-gif-files-by-default/Ok I know this is a stupid question. (But i spend already half an hour on it :( )
After using a.save('myanime') on a animate I can't find the gif file (which is the default extension AFAIK)
To be more specific:
I am using sage on a linux debian (sage recenlty returned to the debian archives !!:D!!)
so I launch sage in terminal (the binary is installed in my /usr/bin )
and the files seemes to be stored in stuff like
/home/myusername/.sage/sage_notebook.sagenb/home/__store__/2/21/212/2123/admin/9 ...
Is it right ?
In case yes it is painful to look for something outside fromethe sage notebook and I would like to integrate the .gif in another web pages. Maybe I can choose where to save the gif ?Laurent BTue, 31 Jan 2017 22:35:02 +0100https://ask.sagemath.org/question/36418/Preserving aspect ratio in animationhttps://ask.sagemath.org/question/26390/preserving-aspect-ratio-in-animation/I'm trying to animate a series of increasing, nested tori. I'm testing the code for the first one, but the aspect ratio isn't behaving, and axes are showing up. I've tried messing with figsize, to no avail. Suggestions?
u,v = var('u,v')
def is_even(n):
return n%2 == 0
def c(n):
return 2/3*(4^(n+1)-4)
def torus(n,u,v):
if is_even(n):
return [(2*4**n + 4**n*cos(u))*cos(v), (2*4**n + 4**n*cos(u))*sin(v) + c(n), 4**n*sin(u)]
else:
return [4**n*sin(u), (2*4**n + 4**n*cos(u))*sin(v) + c(n), (2*4**n + 4**n*cos(u))*cos(v)]
T = []
for i in range(10):
T.append(parametric_plot3d(torus(0,u,v), (u,0,(i+1)*2*pi/9), (v,0,(i+1)*2*pi/9), axes="false"))
a = animate(T)
a.show() Jeff FordMon, 30 Mar 2015 23:34:56 +0200https://ask.sagemath.org/question/26390/Animate wireframe in matplotlib using IDLEhttps://ask.sagemath.org/question/10431/animate-wireframe-in-matplotlib-using-idle/Hi all,
I'm trying to figure out how to animate a wireframe (3d plot) using FuncAnimation. I can understand the animated 2d examples and can create a wireframe plot, but I have trouble updating and plotting the new at each step.
I am trying to make an exercise for a Python introduction course for physicists. The example below should do the basics, i.e. define a mesh, initialise it to 0 everywhere and increase the level at each iteration step. If this basic first step would work I would be ok ... I hope.
Thanks for any help,
Ivo
from matplotlib import pyplot as plt
from pylab import *
from mpl_toolkits.mplot3d.axes3d import Axes3D #-- voor 3d assen
from matplotlib import animation
import time
#============
def test_wave():
#============
#-- initialize grid
Xvalues = linspace(0, 1, 10)
Yvalues = linspace(0, 1, 10)
X,Y = meshgrid(Xvalues, Yvalues)
Z = X+Y
# -----------------------------
def init_wave_profile():
# -----------------------------
for i in range (0,10):
for j in range (0,10):
Z[i][j] = 0
# ----------------------------------------------
def update_wave_profile(itime,Z,p1):
# ----------------------------------------------
print itime
for i in range (0,10):
for j in range (0,10):
Z[i][j] = itime
#-- define plot and initialize profile (flat)
fig = plt.figure(figsize=(6,6))
init_wave_profile()
ax = fig.add_subplot(1, 1, 1, projection='3d')
p1 = ax.plot_wireframe(X, Y, Z, rstride=1, cstride=1, color = 'blue')
ax.set_xlim3d(-0.1,1.1);
ax.set_ylim3d(-0.1, 1.1);
ax.set_zlim3d(-0.5, 1.5);
#-- animate the profile
anim = animation.FuncAnimation(
fig = fig,
func = update_wave_profile,
init_func = init_wave_profile,
frames = 10,
interval = 200,
blit = False,
fargs = (Z, p1)
)
plt.show()
#========
test_wave()
#========
ivoFri, 09 Aug 2013 09:26:45 +0200https://ask.sagemath.org/question/10431/load animationhttps://ask.sagemath.org/question/10034/load-animation/Hi,
I have the following problem:
I'd like to present some calculations in a sage notebook. At one point I'd like to show an animation, but unfortunately it takes some time until the .show() command plots it.
I also do not like to have the animation wiggling araound while I'm presenting the other things before. Hiding the output also doesn't help because I want that it really starts from the beginning on my click and not soemwhere in between.
Is there a possibility to load a saved gif animation? Otherwise is is still possible to open the animation in new window, but it would be neat to have the animation inside the notebook.twchWed, 17 Apr 2013 09:22:06 +0200https://ask.sagemath.org/question/10034/Dancing x-axis in animation [solved]https://ask.sagemath.org/question/9970/dancing-x-axis-in-animation-solved/I'm very new to sage, and I'm trying to make the following animation:
a = animate([sin(20*(x - float(k)))/x for k in srange(0,2*pi,0.5)],
xmin=1, xmax=4, figsize=[3,2])
a.gif(savefile='my_animation.gif', show_path=True)
The problem is that if you look at the animation you'll notice that the x-axis is moving all the time which I find very distracting. Is there a way to tell sage that I want to center the x-axis, so that it stops moving with the animation?RaulMon, 01 Apr 2013 14:29:49 +0200https://ask.sagemath.org/question/9970/'module' object has no attribute 'graphics_filename'https://ask.sagemath.org/question/9617/module-object-has-no-attribute-graphics_filename/Hello everybody!
I typed at Sage Notebook:
a = animate([circle((i,i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)], xmin=0,ymin=0,xmax=2,ymax=2,figsize=[2,2])
a.show()
I got the message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_9.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YSA9IGFuaW1hdGUoW2NpcmNsZSgoaSxpKSwgMS0xLyhpKzEpLCBodWU9aS8xMCkgZm9yIGkgaW4gc3JhbmdlKDAsMiwwLjIpXSwgeG1pbj0wLHltaW49MCx4bWF4PTIseW1heD0yLGZpZ3NpemU9WzIsMl0pCmEuc2hvdygp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpWYgSDe/___code___.py", line 4, in <module>
exec compile(u'a.show()
File "", line 1, in <module>
File "/home/andrei/sage-5.4/local/lib/python2.7/site-packages/sage/plot/animate.py", line 458, in show
self.gif(delay = delay, iterations = iterations)
File "/home/andrei/sage-5.4/local/lib/python2.7/site-packages/sage/plot/animate.py", line 381, in gif
savefile = sage.misc.misc.graphics_filename(ext='gif')
AttributeError: 'module' object has no attribute 'graphics_filename'
Please help me to understand what went wrong. What is missing? Thanks.AndreWinFri, 07 Dec 2012 07:44:40 +0100https://ask.sagemath.org/question/9617/Sage 5.3 in Mountain Lion asks for X11https://ask.sagemath.org/question/9411/sage-53-in-mountain-lion-asks-for-x11/When I attempt to use the `animate` command in Sage 5.3 in Lion, the system asks for X11. What can I do to get `animate` to work properly?calc314Wed, 10 Oct 2012 11:19:37 +0200https://ask.sagemath.org/question/9411/Sage 5.1: Animate command bughttps://ask.sagemath.org/question/9150/sage-51-animate-command-bug/Hi all,
I have installed the both the app version and the command line version of the Sage 5.1 on a MacBook Pro running Lion. Also, I have installed the most recent version of ImageMagick and I've set the environment variables as suggested at the ImageMagick
website. I also checked that ImageMagick is working!
Sage's 'animate' command fails when invoking either version of Sage 5.1 from the command line and then entering "notebook" command to start the browser version of
Sage.
The example is the first one in the 'Animate Plots' section of the Sage's 'Help':
a = animate([circle((i,i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)],
xmin=0,ymin=0,xmax=2,ymax=2,figsize=[2,2])
a.show() # optional -- ImageMagick
Below is the error that is reported by Sage:
============================================================================
convert: memory allocation failed `00000000.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000000.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000001.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000001.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000002.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000002.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000003.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000003.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000004.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000004.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000005.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000005.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000006.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000006.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000007.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000007.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000008.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000008.png' @ error/png.c/ReadPNGImage/3693.
convert: memory allocation failed `00000009.png' @
error/png.c/ReadOnePNGImage/2105.
convert: corrupt image `00000009.png' @ error/png.c/ReadPNGImage/3693.
convert: no images defined
`/private/var/folders/31/r_2f8ryd5ks7xb80nyrbj2cc0000gn/T/tmpbsWwH9/sage\
0.gif' @ error/convert.c/ConvertImageCommand/3044.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_2.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YSA9IGFuaW1hdGUoW2NpcmNsZSgoaSxpKSwgMS0xLyhpKzEpLCBodWU9aS8xMCkgZm9yIGkgaW4gc3JhbmdlKDAsMiwwLjIpXSwgCiAgICAgICAgICAgICAgIHhtaW49MCx5bWluPTAseG1heD0yLHltYXg9MixmaWdzaXplPVsyLDJdKQphLnNob3coKSAjIG9wdGlvbmFsIC0tIEltYWdlTWFnaWNr"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/31/r_2f8ryd5ks7xb80nyrbj2cc0000gn/T/tmpyUOMOA/___code___.py", line 5, in <module>
exec compile(u'a.show() # optional -- ImageMagick
File "", line 1, in <module>
File "/Applications/Sage/local/lib/python2.7/site-packages/sage/plot/animate.py", line 457, in show
self.gif(delay = delay, iterations = iterations)
File "/Applications/Sage/local/lib/python2.7/site-packages/sage/plot/animate.py", line 400, in gif
raise OSError, msg
OSError:
Error: Neither ImageMagick nor ffmpeg appears to be installed. Saving an
animation to a GIF file or displaying an animation requires one of these
packages, so please install one of them and try again.
See www.imagemagick.org and www.ffmpeg.org for more information.
==================================================================================
This might be a permissions error (which causes the images not to be generated)
or perhaps a 64bit vs 32bit lib error. I am not sure!
Note that if the app version of Sage is invoked, Sage is unable to find
ImageMagick's "convert" command.
In a previous response to a similar question it was
suggested that one should modify the "environment.plist" file to set the
environment variables rather than the ".bash_profile file". However, the
problem above seems to be more serious than just finding ImageMagick.
In any case, there should be a better fix than this! An average user should
not be expected to make such changes in their systems! In future versions of
Sage could ImageMagick (or an equivalent) be bundled with Sage?
Regards,
Adam Hausknecht
Department of Mathematics
UMass Dartmouth
ahausknechtFri, 13 Jul 2012 02:17:21 +0200https://ask.sagemath.org/question/9150/imagemagick/animate problemhttps://ask.sagemath.org/question/8688/imagemagickanimate-problem/I have imagemagick installed on my OS X Snow Leopard machine. When I try to do animation on a notebook on my machine I get the error:
"/tmp/sage-mac-app/local/bin/sage-native-execute: line 8: convert:
command not found
Error: ImageMagick does not appear to be installed. Saving an
animation to a GIF file or displaying an animation requires
ImageMagick, so please install it and try again.
See www.imagemagick.org, for example."
Any idea why this would fail even though the convert command works in my terminal prompt?
*edit* I should point out that in the terminal session, the show() method does generate a gif with several pictures. In notebook, however, I get the above error.zscoolWed, 01 Feb 2012 21:38:06 +0100https://ask.sagemath.org/question/8688/Best way to animate an empty chessboard with changing square colorshttps://ask.sagemath.org/question/9096/best-way-to-animate-an-empty-chessboard-with-changing-square-colors/I have an n by n chessboard (without any pieces on it) and a rule that changes the colors of some of the squares. I want an animation showing the chessboard after each change.
My current way is to generate each frame using "list_plot([list of red squares],color=red)+list_plot([list of blue squares],color=blue)+...", then "animate([list of frames])". Example output: http://www.4shared.com/photo/JcjFymIV/pattern.html
Issues with that method:
- animating a list of plots takes ages
- the squares are shown as discs
Can anyone recommend a better way?
chaesloc2Tue, 19 Jun 2012 15:35:54 +0200https://ask.sagemath.org/question/9096/3d animation with tachyonhttps://ask.sagemath.org/question/8947/3d-animation-with-tachyon/Hello!
I'm trying to create a 3d animations, frame per frame. I've discovered that tachyon plotter is very usefull to create images. But after that, I'm unable to make it as animation.
For example, I have copied a code and generate some scenes with tachyon with this:
saved = []
for j in srange(-0.9,1,0.3):
t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0))
t.light((4,3,2), 0.2, (1,1,1))
t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1.0,0,0))
t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.3, opacity=1.0, color=(0,1.0,0))
t.texture('t2', ambient=0.2,diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0))
k=0
for i in srange(-1,j,0.05):
k += 1
t.sphere((i,i^2-0.5,i^3), 0.1, 't%s'%(k%3))
saved.append(t)
In "saved" array I have all the png of the animation I want to do, and I can view it with saved[i].show().
I tried to unite all the frames with the command animate:
animate(saved[i].show() for i in range(0,len(saved)))
But it didn't work. What other alternatives do I have? (without using ffmpeg)
Thank you!RoctivThu, 17 May 2012 10:35:17 +0200https://ask.sagemath.org/question/8947/How to install imagemagick on Sage4.7.2https://ask.sagemath.org/question/8803/how-to-install-imagemagick-on-sage472/I can't find instructions for installing the imagemagick or ffmpeg animition software to run animate on a local sage machine. Can someone here help me? Thanks a lot.
Carl Eberhart
Well, I downloaded the ImageMagick-6.7.6-1.i386.rpm (the download at the top of the list on
http://www.imagemagick.org/script/binary-releases.php
into a sage folder. Then I ran sage and killed the notebook. then I became an su with password sage
then I cd'd to the sage folder and followed the instructions rmp -Uvh Image....etc
Got error indicating 6 library files that couldn't be found. After playing around a bit more, I gave up.
Any suggestions? Thankscarl.eberhartMon, 19 Mar 2012 15:03:25 +0100https://ask.sagemath.org/question/8803/Add a start, stop and pause button to a sage animationhttps://ask.sagemath.org/question/8553/add-a-start-stop-and-pause-button-to-a-sage-animation/Is it possible to add start, stop and pause buttons to a sage animation?sagefanWed, 14 Dec 2011 14:37:38 +0100https://ask.sagemath.org/question/8553/Is there a way to save to to animations in the same avi filehttps://ask.sagemath.org/question/8538/is-there-a-way-to-save-to-to-animations-in-the-same-avi-file/I have two animations, I created using the animate command, which I want to save in the same avi or gif file one below another. Is there a way to do it. I tried (a+b).savefig(), but it saves the two animations on top of one another. I want something like the graphics_array but for animations.
Thanks in advance.ShashankThu, 08 Dec 2011 13:17:02 +0100https://ask.sagemath.org/question/8538/Animate plot of two piecewise functionshttps://ask.sagemath.org/question/8440/animate-plot-of-two-piecewise-functions/Consider a slightly modified version to the workaround to [this](http://ask.sagemath.org/question/868/two-piecewise-defined-functions-in-one-plot) question
sage: k = 5
sage: f = Piecewise([[(-2,1),k],[(1,4),x]])
sage: g = Piecewise([[(-2,1),1],[(1,4),2*x]])
sage: P = plot(f,color='green')
sage: Q = plot(g,linestyle='--')
sage: P+Q
Is it possible to animate this plot say with k ranging from 0 to 10?
I tried:
k = 5
f = Piecewise([[(-2,1),k],[(1,4),x]])
g = Piecewise([[(-2,1),1],[(1,4),2*x]])
P = plot(f,color='green')
Q = plot(g,linestyle='--')
X = P+Q
b = animate([X for k in srange(0,10)],xmin=0,xmax=4,figsize=[5,5])
b
b.show()
but it calculates for minutes and doesn't show up a result. (I tried examples from the documentation which worked fine).
I also tried this:
t = var('t')
k = var('k')
def f(t,k):
if t <=1:
return t
else:
return k
def g(t,k):
if t <=1:
return 1
else:
return 2*t
@interact
def _(k=(0,10)):
p1=plot(f(t,k),(t,0,3),ymax=10,ymin=0,color='green')
p2=plot(g(t,k),(t,0,3))
show(p1 + p2)
However the piecewise defined functions don't work in this case.sagefanFri, 04 Nov 2011 18:50:22 +0100https://ask.sagemath.org/question/8440/Creating plots in parallelhttps://ask.sagemath.org/question/8271/creating-plots-in-parallel/Ok, even though my last question about @parallel was foolish, here is another one. I want to create a simple animation that consists of many plots. It takes a minute or two on my computer to produce. But it would be nice if I could harness the idle CPU's I have and create the frames for the animation in parellel. I thought this would be easy like this:
x = var('x')
FRAMES = 10
@parallel
def frame(i):
return plot(sin(i*x), (x, 0, pi))
P = [ p[1] for p in frame(range(1,FRAMES+1)) ]
#A = animate(blah, blah, ...)
and what I get back (in the Sage notebook) is:
invalid load key, 'x'.
Killing any remaining workers...
Any idea what is going wrong here?
benjaminfjonesSat, 13 Aug 2011 01:11:09 +0200https://ask.sagemath.org/question/8271/creating a fourier series animationhttps://ask.sagemath.org/question/8062/creating-a-fourier-series-animation/Hello,
I want to create an animation of sum((-1)^(n-1)*sin(n*x)/n,n,1 , k)
and show that as the number of terms 'k' in the partial sums increase, the sum converges to x/2 i.e looks more and more like the graph of x/2.
My first try is
**a = animate([(sum((-1)^(n-1)*sin(n*x)/n,n,1 , k))] for k in range (1,50,1))**
But that returns me an error
*Traceback (click to the left of this block for traceback)
...
AttributeError: 'int' object has no attribute '_maxima_'*
Also I want to include a static graph of x/2 in the background of the animation so that it is easy to observe that the series converges to x/2. how to do this?ebsSat, 09 Apr 2011 05:04:43 +0200https://ask.sagemath.org/question/8062/animate 3d plots?https://ask.sagemath.org/question/7666/animate-3d-plots/Is there an animation function for 3d plots? Specifically, I'm looking to animate some plots drawn with Tachyon, but I don't see any animation functions either in the [Tachyon documentation](http://www.sagemath.org/doc/reference/sage/plot/plot3d/tachyon.html) or in the [3d base classes documentation](http://www.sagemath.org/doc/reference/sage/plot/plot3d/base.html). I have seen that there is an animate function for [2d plots](http://www.sagemath.org/doc/reference/sage/plot/animate.html), but it says that the input needs to be a "graphics object", and I don't think Tachyon objects are recognized as such. So maybe modifying the 2d animation functions could do what I want, but is there something else already available?
For an example, an animation where the curve changes color from magenta to white would be great:
<pre>
sage: f = lambda t: (t,t^2,t^3)
sage: t = Tachyon(camera_center=(5,0,4))
sage: t.texture('t')
sage: t.light((-20,-20,40), 0.2, (1,1,1))
sage: t.parametric_plot(f,-5,5,'t',min_depth=6)
sage: t.show()
</pre>
p.s. If this **is** already available, I'll volunteer to add information about it to the Tachyon documentation.nilesSat, 04 Sep 2010 10:59:25 +0200https://ask.sagemath.org/question/7666/