Để tạo quiver plot (biểu đồ vectơ) trong tọa độ cực (polar coordinates) với Matplotlib:
- Thiết lập kích thước figure và padding
- Tạo dữ liệu
radii, thetas, theta, rbằng numpy - Tạo figure mới
- Thêm subplot với
polar=True - Tạo poly collections của các mũi tên bằng
quiver() - Hiển thị bằng
show()
Ví dụ mã nguồn
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True radii = np.linspace(0, 1, 5) thetas = np.linspace(0, 2 * np.pi, 20) theta, r = np.meshgrid(thetas, radii) f = plt.figure() ax = f.add_subplot(polar=True) ax.quiver(theta, r, np.cos(theta) - np.sin(theta), np.sin(theta) + np.cos(theta)) plt.show()
Kết quả
Biểu đồ vectơ trên tọa độ cực: mũi tên chỉ hướng và độ lớn tại các điểm (r, θ).

Tham số quiver: quiver(theta, r, u, v) với (u, v) là thành phần vectơ trong hệ tọa độ cực.