Để hiển thị số thường thay vì ký hiệu khoa học (1e3) trên trục log-log, dùng ax.xaxis.set_minor_formatter(mticker.ScalarFormatter()).
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu x, y và vẽ scatter.
- Đặt scale log cho 2 trục: ax.set_xscale('log'), ax.set_yscale('log').
- Import ticker as mticker, đặt formatter: ax.xaxis.set_minor_formatter(mticker.ScalarFormatter()).
- Hiển thị bằng show().
Ví dụ
import numpy as np
from matplotlib import pyplot as plt, ticker as mticker
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.array([1, 7, 6, 4, 0])
y = np.array([6, 2, 3, 5, 1])
plt.scatter(y, x, c=x, cmap="copper")
ax = plt.gca()
ax.set_xscale('log')
ax.set_yscale('log')
ax.xaxis.set_minor_formatter(mticker.ScalarFormatter())
plt.show()
Kết quả
