Để vẽ dữ liệu true/false hoặc active/inactive trong Matplotlib:
- Thiết lập kích thước hình và điều chỉnh khoảng đệm subplot.
- Tạo dữ liệu numpy với True/False.
- Tạo figure mới.
- Thêm axes vào figure.
- Dùng imshow() hiển thị dữ liệu như hình ảnh 2D raster.
- Hiển thị hình bằng show().
Ví dụ
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.random((20, 20)) > 0.5 fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(data, aspect='auto', cmap="copper", interpolation='nearest') plt.show()
Kết quả
