Để vẽ vòng tròn màu dựa trên colormap, ta dùng lớp colorbar và colormap copper.
Các bước thực hiện
- Thiết lập kích thước hình và khoảng đệm.
- Tạo hình mới bằng figure().
- Thêm trục vào hình bằng add_axes() với projection='polar'.
- Đặt hướng trục.
- Chuẩn hóa dữ liệu tuyến tính bằng lớp Normalize.
- Vẽ colorbar trên trục hiện có.
- Đặt độ hiển thị của artist.
- Tắt trục X và Y.
- Hiển thị hình bằng show().
Ví dụ
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()
Kết quả
