如何从 Matplotlib 对数对数图中删除科学计数法?
matplotlibpythondata visualization更新于 2025/6/3 6:04:17
要从 matplotlib 对数对数图中删除科学计数法,我们可以使用 ax.xaxis.set_minor_formatter(mticker.ScalarFormatter()) 语句。
步骤
- 设置图形大小并调整子图之间和周围的填充。
- 使用 numpy 创建 x 和 y 数据点。
- 使用 scatter() 方法绘制 x 和 y 数据点。
- 使用 set_xscale() 和 set_yscale() 方法设置 x 和 y 轴的刻度。
- 要删除科学计数法,请使用格式刻度值为数字。
- 要显示图形,请使用show() 方法。
示例
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()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

