Matplotlib không hỗ trợ trực tiếp vẽ phương trình ngầm, nhưng có thể dùng contour plot.
- Tạo xrange, yrange bằng np.arange.
- Tạo lưới tọa độ bằng np.meshgrid.
- Định nghĩa phương trình: equation = sin(x) - cos(y)^2.
- Vẽ contour tại level 0: plt.contour(x, y, equation, [0]).
- Hiển thị bằng show().
Ví dụ
from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True delta = 0.025 xrange = np.arange(-5.0, 20.0, delta) yrange = np.arange(-5.0, 20.0, delta) x, y = np.meshgrid(xrange, yrange) equation = np.sin(x) - np.cos(y)**2 plt.contour(x, y, equation, [0]) plt.show()
Kết quả
Đường contour của phương trình sin(x) - cos²(y) = 0.
Có thể dùng scipy.optimize để vẽ chính xác hơn.