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

การพลอตวงสีแบบขั้ว (Polar Color Wheel) จาก Colormap ใน Matplotlib

สามารถสร้างวงสีแบบขั้วได้โดยใช้ ColorbarBase บนแกนโฉมวง (polar projection) และกำหนด colormap เช่น 'copper' พร้อมปรับ normalization ให้ครอบคลุม 0 ถึง 2π

ขั้นตอนการทำงาน

  1. ตั้งค่าขนาดรูปและเลย์เอาต์
  2. สร้างฟิกเกอร์และเพิ่มแกนโฉมวงด้วย add_axes(projection='polar')
  3. ตั้งค่าทิศทางแกนและ normalization (0 ถึง 2π)
  4. สร้าง ColorbarBase ด้วย colormap ที่ต้องการ
  5. ปิดขอบและแกน แล้วแสดงผล

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

import numpy as np
from matplotlib import pyplot as plt, cm, colors, colorbar

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

fig = plt.figure()
display_axes = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar')
display_axes._direction = 2 * np.pi

norm = colors.Normalize(0.0, 2 * np.pi)
cb = colorbar.ColorbarBase(display_axes, cmap=cm.get_cmap('copper', 2056), norm=norm, orientation='horizontal')
cb.outline.set_visible(False)
display_axes.set_axis_off()
plt.show()

ผลลัพธ์

การพลอตวงสีแบบขั้ว (Polar Color Wheel) จาก Colormap ใน Matplotlib