Matplotlib:将 xticks 显示为对数对数刻度中的整数

Matplotlib: Display xticks as integers in log-log scale

我正在尝试用我已有的数据复制以下散点图。该图在对数对数刻度(黑点)上绘制了 F_n vs n,但 x 轴和 y 轴表示实际数字而不是 10 的幂。蓝线是最佳拟合线,可以忽略。基于 this question, I have tried to formate the x-axis using ScalarFormatter and the tick-formating API but I am unable to get the proper formatting to display arbitrary numbers like (2,5,20,50). Furthermore, how should one selectively pick the ticks for the y-axis, I tried the LogLocator 的答案,但它也不起作用。

欢迎任何帮助或建议。提前致谢!

实现这一目标的一种方法是使用 xticksyticks。这是一个例子:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(1, 200)
y = 0.1 * (x / x[0])**(np.log10(1e-07/0.1) / np.log10(x[-1]/x[0]))

plt.figure()
plt.plot(x, y)
plt.xscale("log")
plt.yscale("log")
plt.xticks([1, 2, 5, 10, 20, 50, 100, 200], [1, 2, 5, 10, 20, 50, 100, 200])
plt.yticks([0.01, 1e-04, 1e-06], [0.01, "1e-04", 1e-06])
plt.minorticks_off()
plt.show()