forked from exo7math/deepmath-exo7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonxy_matplolib_4.py
More file actions
52 lines (33 loc) · 1.08 KB
/
pythonxy_matplolib_4.py
File metadata and controls
52 lines (33 loc) · 1.08 KB
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
import numpy as np
import matplotlib.pyplot as plt
n = 100
VX = np.linspace(-3.0, 3.0, n)
VY = np.linspace(-3.0, 3.0, n)
X,Y = np.meshgrid(VX, VY)
def f(x,y): # from matlab website
z = 3 * (x-1)**2 * np.exp(-(y+1)**2-x**2) - 1/3 * (np.exp(-(x+1)**2-x**2)) + (10*x**3-2*x+10*y**5)*np.exp(-x**2-y**2)
return z
Z = f(X,Y)
# Contour - niveaux donnés avec valeurs
mes_niveaux = np.arange(-5,5,1)
trace = plt.contour(X, Y, Z, mes_niveaux)
plt.clabel(trace, inline=True, fontsize=8)
plt.axis('equal')
# plt.savefig('pythonxy-niveau-2d-2.png')
plt.show()
########### Vue 3D ###########
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.view_init(50, -50)
ax.plot_surface(X, Y, Z, alpha=1)
# plt.savefig('pythonxy-niveau-3d-2.png')
plt.show()
ax.plot_surface(X, Y, Z,cmap=plt.cm.CMRmap)
ax.plot_surface(X, Y, Z,cmap=plt.cm.Spectral)
# Fig 3. Contour rempli
# plt.contourf(X, Y, Z,mes_niveaux, cmap='hot')
# plt.colorbar();
# plt.savefig('pythonxy-niveau-3.png')
# niveaux = plt.contour(X, Y, Z,mes_niveaux, cmap='RdGy') # essayer contour/contourf()
#