-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_utils.py
More file actions
27 lines (21 loc) · 802 Bytes
/
plot_utils.py
File metadata and controls
27 lines (21 loc) · 802 Bytes
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
import numpy as np
import matplotlib.pyplot as plt
def plot_surface(function, x_range = (-6,6), y_range=(-6,6), spacing=30):
X, Y = create_mesh(x_range, y_range, spacing)
Z = function(X, Y)
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
cmap='plasma', edgecolor='none')
ax.set_title('surface')
return ax
def create_mesh(x_range, y_range, spacing):
x = np.linspace(x_range[0], x_range[1], spacing)
y = np.linspace(y_range[0], y_range[1], spacing)
return np.meshgrid(x, y)
def sample_function_1(x,y):
return np.sin(np.sqrt(x ** 2 + y ** 2))
def sample_function_2(x,y):
return (x ** 2 -4)**2 + y ** 2
if __name__ == '__main__':
ax = plot_surface(sample_function_2, (-3,3), (-4,4), 30)
plt.show()