Để vẽ nhiều hình song song:
- Tạo dữ liệu ngẫu nhiên bằng numpy.
- Thêm subplot, nrows=1, ncols=4, index=1.
- Hiển thị dữ liệu dạng ảnh 2D bằng imshow() với cmap="Blues_r".
- Thêm subplot index=2, cmap="Accent_r".
- Thêm subplot index=3, cmap="terrain_r".
- Thêm subplot index=4, cmap="twilight_shifted_r".
- Hiển thị bằng show().
Ví dụ
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) plt.subplot(1, 4, 1) plt.imshow(data, cmap="Blues_r") plt.subplot(1, 4, 2) plt.imshow(data, cmap="Accent_r") plt.subplot(1, 4, 3) plt.imshow(data, cmap="terrain_r") plt.subplot(1, 4, 4) plt.imshow(data, cmap="twilight_shifted_r") plt.show()
Kết quả
