Skip to content

Instantly share code, notes, and snippets.

@germannp
Created April 13, 2015 15:05
Show Gist options
  • Save germannp/ec179f032cc4c97ee487 to your computer and use it in GitHub Desktop.
Save germannp/ec179f032cc4c97ee487 to your computer and use it in GitHub Desktop.
Matplotlib script to create a rotating animation.
"""Save frames from different POVs"""
import os
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
import innear
# Set up plot
worm = pd.DataFrame({'x': np.random.randn(500),
'y': np.random.randn(500),
'z': np.random.randn(500)*5})
sns.set(style='white')
ax = plt.subplot(1,1,1, projection='3d')
ax.scatter(worm['x'], worm['y'], worm['z'])
innear.equalize_axis3d(ax)
ax.view_init(elev=0)
ax.axis('off')
# Rotation
delev = 30
for elevation in np.arange(-delev, 181, delev):
ax.view_init(elev=elevation)
plt.savefig('rotanim_' + str(elevation) + '.png')
# That is pretty pedestrian -- but the first axes suck :>
os.remove('rotanim_' + str(-delev) + '.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment