Create 3d gif with python3

I found a blog that writes cool 3D in Python

http://geoffboeing.com/2015/04/animated-3d-plots-python/

This blog is cool, so buy the Japanese version, make it, and share it!

The bottom line is that this blog alone won't work with Python 3. In the first place, images2gif is python2.

So, as soon as you google "images2gif python3", you will reach the following Github

https://github.com/isaacgerg/images2gif

For the time being, do this locally, python images2gif.py and hopefully. The following Gif can be created.

test.gif

And integrate with the one on the blog above!

If you have already installed images2gif with python3, delete it with pip uninstall images2gif or something.

Then import images2gif.py brought directly from Github above.

Import what you need (use as it is from the blog)

import pandas as pd, numpy as np, random
import matplotlib.pyplot as plt, matplotlib.cm as cm
from mpl_toolkits.mplot3d import Axes3D
import IPython.display as IPdisplay
import glob
from PIL import Image as PIL_Image
from images2gif import writeGif

Write 3d images in Axes 3D (I wrote it myself)

gif_file_name = '3d_test'

x = np.arange(-3, 3, 0.25)
y = np.arange(-3, 3, 0.25)

x = np.arange(-3, 3, 0.25)
y = np.arange(-3, 3, 0.25)
X, Y = np.meshgrid(x, y)
Z = np.sin(X)+ np.cos(Y)

fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X, Y, Z)

Save 100 images with different angles (use blog as it is)

ax.elev = 89.9
ax.azim = 270.1
ax.dist = 11.0

for n in range(100):
    if n >= 20 and n <= 22:
        ax.set_xlabel('')
        ax.set_ylabel('') #don't show axis labels while we move around, it looks weird
        ax.elev -= 0.5 #start by panning down slowly
    if n >= 23 and n <= 36:
        ax.elev -= 1.0 #pan down faster
    if n >= 37 and n <= 60:
        ax.elev -= 1.5
        ax.azim += 1.1 #pan down faster and start to rotate
    if n >= 61 and n <= 64:
        ax.elev -= 1.0
        ax.azim += 1.1 #pan down slower and rotate same speed
    if n >= 65 and n <= 73:
        ax.elev -= 0.5
        ax.azim += 1.1 #pan down slowly and rotate same speed
    if n >= 74 and n <= 76:
        ax.elev -= 0.2
        ax.azim += 0.5 #end by panning/rotating slowly to stopping position
    if n == 77:
        ax.set_xlabel('X')
        ax.set_ylabel('Y')
        ax.set_zlabel('Z')
    fig.suptitle('Practice')
    fig.savefig('images/' + 'img' + str(n).zfill(3) + '.png')

Finally create a gif from 100 images

images = [PIL_Image.open(image) for image in glob.glob('images/*.png')]
file_path_name = 'images/3d_test.gif'
writeGif(file_path_name, images, duration=0.1)

Now you have the following! (The image is compressed and the gif does not work w ...)

3d_test.gif

There is no way, so create a 5-frame version ↓

3d_test_sm.gif

Recommended Posts

Create 3d gif with python3
Create 3D scatter plot with SciPy + matplotlib (Python)
Create gif video in Python
Create a directory with python
Create an animated GIF local server with Python + Flask
[Python] How to create a 2D histogram with Matplotlib
Create a 2d CAD file ".dxf" with python [ezdxf]
Create plot animation with Python + Matplotlib
Create Awaitable with Python / C API
3D skeleton structure analysis with Python
Create folders from '01' to '12' with python
Solve ABC166 A ~ D with Python
Create a virtual environment with Python!
Create an Excel file with Python3
Load gif images with Python + OpenCV
FizzBuzz with Python3
Create a Python function decorator with Class
Scraping with Python
Automatically create Python API documentation with Sphinx
Create wordcloud from your tweet with python3
Statistics with python
Build a blockchain with Python ① Create a class
Scraping with Python
Python with Go
[Python] Create a virtual environment with Anaconda
2D FEM stress analysis program with Python
Let's create a free group with Python
Quickly create an excel file with Python #python
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
Create Python + uWSGI + Nginx environment with Docker
Create and decrypt Caesar cipher with python
python starts with ()
Create miscellaneous Photoshop videos with Python + OpenCV ③ Create miscellaneous Photoshop videos
with syntax (Python)
Create Excel file with Python + similarity matrix
Solve AtCoder ABC168 with python (A ~ D)
Create a word frequency counter with Python 3.4
Bingo with python
[Python] Quickly create an API with Flask
Zundokokiyoshi with python
Create an English word app with python
Excel with Python
Microcomputer with Python
Cast with python
Create a frame with transparent background with tkinter [Python]
Create a GIF file using Pillow in Python
Create test data like that with Python (Part 1)
[Python] limit axis of 3D graph with Matplotlib
Create polka dot wallpaper with Python Image Library
Create a LINE BOT with Minette for Python
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Solve A ~ D of yuki coder 247 with python
Create a color bar with Python + Qt (PySide)