Để thiết lập lưới ngang, dọc, major, minor độc lập, ta dùng grid().
Các bước
- Thiết lập kích thước hình và điều chỉnh khoảng đệm subplot.
- Tạo figure và subplots.
- Tạo lưới ngang cho major ticks.
- Đặt minor locator cho axes.
- Dùng grid() tạo lưới minor.
- Hiển thị hình bằng show().
Ví dụ
import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() ax.yaxis.grid(which="major", color='r', linestyle='-', linewidth=2) ml = MultipleLocator(0.10) ax.xaxis.set_minor_locator(ml) ax.xaxis.grid(which="minor", color='k', linestyle='-.', linewidth=0.7) plt.show()
Kết quả
