Ask Your Question
1

Animating plots in Jupyter/Sagemath

asked 2022-06-17 20:59:11 +0100

mn124700 gravatar image

I'm using SageMath 9.6 with Jupyter on OSX. I have a plot (psi_plot_1) that I want to animate:

plot_graph = [plot(psi_plot_1(x,t).real(),[x,0,1],color='red',ymin=-1.5,ymax=1.5) for t in sxrange(0,2,.1)]
a=animate(plot_graph)
a.show()

All I get is a statement saying "Animation 20 frames" rather than an actual animation. I tried installing ffmpeg and ImageMagick using brew from the OSX terminal, but the problems persist.

How do I get this to work? THanks, Eric

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2022-06-17 21:45:21 +0100 )edit

Do the commands from sage.features.imagemagick import ImageMagick; ImageMagick().require() return without error? How about from sage.features.ffmpeg import FFmpeg; FFmpeg().require()? (The animation works for me with ImageMagick installed but not ffmpeg. Maybe try deleting ffmpeg?)

John Palmieri gravatar imageJohn Palmieri ( 2022-06-17 23:53:53 +0100 )edit

I tried what you suggested. I get the following error... Is this a python PATH issue? How do I fix? Thanks


FeatureNotPresentError Traceback (most recent call last) /var/folders/h5/lf9qnqx523s8_f80_bkb4j3c0000gp/T/ipykernel_2817/568311210.py in <module> ----> 1 from sage.features.imagemagick import ImageMagick; ImageMagick().require()

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/features/__init__.py in require(self) 207 presence = self.is_present() 208 if not presence: --> 209 raise FeatureNotPresentError(self, presence.reason, presence.resolution) 210 211 def __repr__(self):

FeatureNotPresentError: imagemagick is not available. Ex

mn124700 gravatar imagemn124700 ( 2022-06-21 00:58:20 +0100 )edit

On my machine, ImageMagick installs into /usr/local/bin. Try evaluating os.environ['PATH'] from within Sage and see if /usr/local/bin is listed.

John Palmieri gravatar imageJohn Palmieri ( 2022-06-21 03:58:59 +0100 )edit

I get...

    '/Applications/SageMath-9-6.app/Contents/Frameworks/Sage.framework/Versions/9.6/build/bin:
/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/bin:
/var/tmp/sage-9.6-current/local/bin:
/usr/bin:/bin:
/usr/sbin:/sbin'

On my system, it looks like it's installed to /usr/local/lib

How do I add the necessary path? Or should I try to install ImageMagick to a different directory?

Thanks, Eric

mn124700 gravatar imagemn124700 ( 2022-06-22 17:49:16 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-06-24 22:21:14 +0100

updated 2022-06-25 01:35:59 +0100

One option: in any notebook where you want to use, for example, ImageMagick's binary "convert", first you have to find that file. On my machine it's in /usr/local/bin. Then add this to the notebook:

import os
os.environ['PATH'] += ':/usr/local/bin'

(The leading colon is important: PATH is a list of directories separated by colons. If you want this to be platform independent, then I guess you should use os.environ['PATH'] += os.pathsep + '/usr/local/bin': see https://docs.python.org/3/library/os.....)

Another option is to automatically add /usr/local/bin (or whatever directory is appropriate) to PATH for any notebook. You will need to create a Jupyter configuration file for this, and I can't see a way to do this while running Jupyter: you will have to use the Terminal. Locate the SageMath app; on my computer it is on my Desktop: it's /Users/palmieri/Desktop/SageMath-9-6.app. From the Terminal, do this, replacing the first part with the location of your SageMath app:

% /Users/palmieri/Desktop/SageMath-9-6.app/Contents/Frameworks/Sage.framework/Versions/9.6/venv/bin/ipython profile create

This will print a message along these lines:

[ProfileCreate] Generating default config file: '/Users/palmieri/.ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: '/Users/palmieri/.ipython/profile_default/ipython_kernel_config.py'

Now edit either of these files, I don't think it matters which one. These instructions come from @slelievre, via https://groups.google.com/g/sage-supp.... Find these lines:

## lines of code to run at IPython startup.
#  Default: []
# c.InteractiveShellApp.exec_lines = []

Replace the last line with

c.InteractiveShellApp.exec_lines = ["import os; os.environ['PATH'] += ':/usr/local/bin' "]

(Make sure to remove the "#" at the start: that's a comment character.)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-06-17 20:59:11 +0100

Seen: 910 times

Last updated: Jun 25 '22