Các bước
- Thiết lập kích thước hình và padding.
- Tạo dữ liệu
x, y bằng numpy.
- Tạo figure và subplots.
- Vẽ đồ thị bằng
plot().
- Đặt vị trí minor ticks bằng
set_minor_locator() (ví dụ AutoMinorLocator(2)).
- Hiển thị minor grid bằng
grid(which='minor').
- Gọi
show().
Ví dụ
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import AutoMinorLocator
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(1, 10, 100)
y = np.log(x)
fig, ax = plt.subplots()
ax.plot(x, y)
minor_locator = AutoMinorLocator(2)
ax.xaxis.set_minor_locator(minor_locator)
plt.grid(which='minor')
plt.show()
Kết quả
