Created
March 26, 2015 06:50
-
-
Save yassu/36374f6d0c4e6de65954 to your computer and use it in GitHub Desktop.
If alpha + beta = X and alpha*beta=Y, plot graph of each alpha^n + beta^n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A very simple 'animation' of a 3D plot | |
""" | |
from mpl_toolkits.mplot3d import axes3d | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import time | |
def generate(X, Y, count=10): | |
yield 2 | |
yield X | |
vals = [2, X] | |
for _ in range(count - 2): | |
res = X*vals[-2] - Y*vals[-1] | |
yield res | |
vals.append(res) | |
plt.ion() | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
xs = np.linspace(-1, 10, 50) | |
ys = np.linspace(-1, 10, 50) | |
X, Y = np.meshgrid(xs, ys) | |
N = 30 | |
wframe = None | |
tstart = time.time() | |
Zs = list(generate(X, Y, count=N)) | |
for n in range(N): | |
oldcol = wframe | |
Z = Zs.pop(0) | |
wframe = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2) | |
# Remove old line collection before drawing | |
if oldcol is not None: | |
ax.collections.remove(oldcol) | |
plt.pause(0.5) | |
print ('FPS: %f' % (100 / (time.time() - tstart))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment