Preferences to generate animated GIFs from Python on Mac

I had a hard time installing ImageMagick and PythonMagick, the libraries needed to make animated GIFs in Python, so I'll note how to do it here.

anim_test.gif Like this quadratic_decent_anim-compressor.gif Like this normdist_decent_0.0_anim-compressor.gif You can generate something like this.

0. Environment

1. Install Image Magick

sudo dscl . -append /Groups/wheel GroupMembership <user name>
sudo chmod -R g+w /usr/local/include/ 
sudo chmod -R g+w /usr/local/share/man/man5
sudo chmod -R g+w /usr/local/lib/
brew link libpng
brew install imagemagick

2. Install Python Magick

brew install boost
brew install boost-python
sudo chmod -R g+w /usr/local/share/info
brew link libtool

Download Python Magick http://www.imagemagick.org/download/python/

cd /path/to/PythonMagick-0.9.12
./configure
make

I get an error. .. ..

error


CXXLD    _PythonMagick.la
clang: warning: argument unused during compilation: '-pthread'
ld: warning: directory not found for option '-L/usr/local/Cellar/freetype/2.6/lib'

When I looked it up, in my environment

/usr/local/Cellar/freetype/2.6_1/lib/

Seems to be the correct path.

Find the file to modify.

find ./ -type f -print | xargs grep 'freetype' -n

Since it was directly under / path / to / PythonMagick-0.9.12,

vi _PythonMagick.la 

So, I corrected the path. take heart,

make
sudo make install

3. Trial

%matplotlib inline 
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation as ani
plt.style.use('ggplot')

num_frame = 80.
x_range= 7

def animate(nframe):
    global num_frame
    plt.clf()
    a = ((5*nframe/num_frame) -.5) * np.pi
    x = np.linspace(-x_range, x_range, 200)
    y = np.sin(x+a)
    
    plt.xlim(-x_range, x_range)
    plt.ylim(-1.1,1.1)
    plt.plot(x, y, c="b")

fig = plt.figure(figsize=(12,5))
anim = ani.FuncAnimation(fig, animate, frames=int(num_frame))
anim.save('anim_test.gif', writer='imagemagick', fps=5, dpi=64)

It's done!

anim_test.gif

Recommended Posts

Preferences to generate animated GIFs from Python on Mac
Update Python on Mac from 2 to 3
Update python on Mac to 3.7-> 3.8
Steps to install python3 on mac
Call C / C ++ from Python on Mac
How to rebuild python environment from pyenv on Mac environment (El Capitan)
How to erase Python 2.x on Mac.
Connecting from python to MySQL on CentOS 6.4
python on mac
How to generate a Python object from JSON
Use Tor to connect from urllib2 [Python] [Mac]
Changes from Python 3.0 to Python 3.5
Install Python on Mac
Install Python 3 on Mac
Install Python 3.4 on Mac
Steps to install the latest Python on your Mac
From python to running instance on google cloud platform
[Python3] I want to generate harassment names from Japanese!
I want to AWS Lambda with Python on Mac!
Post from Python to Slack
Cheating from PHP to Python
Install pygame on python3.4 on mac
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Handling of python on mac
Install pandas 0.14 on python3.4 [on Mac]
Notes on installing Python on Mac
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Connect to centos6 on virtualbox with ssh connection from Mac
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Call Matlab from Python to optimize
Building a Python environment on Mac
If python on mac goes missing
Python 3.6 on Windows ... and to Xamarin.
How to install mysql-connector-python on mac
Create folders from '01' to '12' with python
Steps to install matplotlib on Mac
Introduction to Python Hands On Part 1
Notes on using MeCab from Python
Post from python to facebook timeline
Ansible playbook for setting up Python preferences using pyenv on Mac
Create a Python environment on Mac (2017/4)
[Lambda] [Python] Post to Twitter from Lambda!
Python environment construction memo on Mac
Install Python 3.7 Anaconda on MAC, but Python 2
Things to note when running Python on EC2 from AWS Lambda
Install python3 on Mac (El Capitan)
I want to know if you install Python on Mac ・ Iroha
How to install OpenCV on Mac
[python] Copy script to generate copy log
Simple code to call a python program from Javascript on EC2
Connect to utf8mb4 database from python
Python (from first time to execution)
View Mac desktop notifications from Python
Post images from Python to Tumblr
Environment construction of python3.8 on mac
[Python + heroku] From the state without Python to displaying something on heroku (Part 1)
Notes on accessing dashDB from python
If Python 3.5.0 installation fails on Mac
How to access wikipedia from python
Python to switch from another language