Trong bài viết này, chúng ta lấy mã chương trình để trình bày cách làm cho biểu đồ 3D tương tác bằng Jupyter Notebook.
Các bước
Tạo figure mới hoặc kích hoạt figure hiện có.
Tạo fig, ax bằng subplots(), mặc định nrows=ncols=1, projection='3d'.
Lấy x, y, z bằng np.cos và np.sin.
Vẽ wireframe 3D, dùng x, y, z, color="red".
Đặt tiêu đề cho trục hiện tại.
Hiển thị figure bằng plt.show().
Ví dụ
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
u, v = np.mgrid[0:2 * np.pi:30j, 0:np.pi:20j]
x = np.cos(u) * np.sin(v)
y = np.sin(u) * np.sin(v)
z = np.cos(v)
ax.plot_wireframe(x, y, z, color="red")
ax.set_title("Sphere")
plt.show()
Kết quả
