1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import math
def animation(angle_vertical):
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
import math
fig = plt.figure()
ax = fig.gca(projection='3d')
#creation des données
X = np.linspace(-4, 4, 100)
Y = np.linspace(-4, 4, 100)
#Z = np.array([[math.cos(math.sqrt(y**2+x**2))+0.1*math.sin(x**2+y**2) for y in Y] for x in X])
Z = np.array([[x*y/(x**2+y**2) for y in Y] for x in X])
X, Y = np.meshgrid(X, Y)
#ax.plot_surface(X, Y, Z, cmap=matplotlib.cm.Spectral)
#help(matplotlib.cm)
ax.plot_surface(X, Y, Z, cmap=matplotlib.cm.Purples)
ax.plot_surface(X, Y, Z, cmap=matplotlib.cm.Reds)
for angle in range(0, 360//4, 1):
ax.view_init(angle_vertical, angle)
plt.draw()
plt.pause(.01)
plt.close()
return angle_vertical
def surface(f,xmin=-10,xmax=10,ymin=-10,ymax=10):
"""
affiche les courbes en 3d
affiche un surface
"""
from mpl_toolkits.mplot3d import Axes3D
#calcul de la fonction
X = np.linspace(xmin,xmax,1000)
Y = np.linspace(ymin,ymax,1000)
Z = np.array([[f(float(x),float(y)) for y in Y] for x in X])
X, Y = np.meshgrid(X, Y)
#affichage simple
fig = plt.figure()
ax = fig.gca(projection="3d")
ax.plot_surface(X, Y, Z)
plt.show()
def vrai_surface(gf,gxmin,gxmax,gymin,gymax):
"""
fait une animation en 3D des courbes
"""
pass
def f(x,y):
return math.cos(math.sqrt(y**2+x**2))+0.1*math.sin(x**2+y**2)
animation(35) |
Partager