Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách vẽ đường sin trên trục cực (polar axes) trong Matplotlib


Vẽ hàm sin trên trục cực: tạo subplot với projection='polar', vẽ dữ liệu x, y.

  • Thiết lập figure.
  • Tạo axes polar: fig.add_subplot(projection='polar').
  • Tạo x, y = sin(x^2).
  • Vẽ ax.plot(x, y).

Ví dụ minh họa

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
x = np.linspace(-5, 5, 100)
y = np.sin(x**2)
ax.plot(x, y, color='red', lw=3)
plt.show()

Kết quả đầu ra

Cách vẽ đường sin trên trục cực (polar axes) trong Matplotlib