Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีสร้าง Minor Ticks สำหรับ Polar Plot ใน Matplotlib

วาด Minor Ticks (เส้นเล็ก) รอบ Polar Plot ทุก 10 องศา

ขั้นตอน

  1. ตั้งค่าขนาด Figure
  2. สร้างข้อมูล Radius และ Theta
  3. เพิ่ม Subplot แบบ Polar
  4. วนลูปมุม 0-360° ทุก 10° วาดเส้นสั้นจาก rmax ถึง 0.97*rmax
  5. แสดงผล

ตัวอย่างโค้ด

import numpy as np
import matplotlib.pyplot as plt

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

r = np.arange(0, 5, 0.1)
theta = 2 * np.pi * r

ax = plt.subplot(111, projection='polar')
tick = [ax.get_rmax(), ax.get_rmax() * 0.97]

for t in np.deg2rad(np.arange(0, 360, 10)):
    ax.plot([t, t], tick, lw=1, color="red")

plt.show()

ผลลัพธ์

Polar Plot พร้อม Minor Ticks สีแดงทุก 10 องศา

วิธีสร้าง Minor Ticks สำหรับ Polar Plot ใน Matplotlib