Để xuất ảnh chất lượng cao (high quality) từ Matplotlib, dùng DPI lớn (>600) và định dạng vector (PDF, EPS) hoặc PNG high-DPI.
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu ma trận 2D.
- Hiển thị bằng imshow().
- Lưu file: plt.savefig("myimage.eps", dpi=1200) (EPS vector, DPI cao).
- Hiển thị bằng show().
Ví dụ
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
data = np.array([[0.1, 0.7, 0.6, 0.3], [0.2, 0.6, 0.5, 0.2], [0.8, 0.3, 0.80, 0.01], [0.3, 0.4, 0.2, 0.1]])
plt.imshow(data, interpolation="nearest", cmap="RdYlGn_r")
plt.savefig("myimage.eps", dpi=1200)
plt.show()
Kết quả
