Python:使用 matplotlib 更改绘图的标签

Python: change labels of a plot using matplotlib

我想更改绘图的标签

fig=figure(figsize=(7.5,7.5))
labels = [0,0.00001,0.0001,0.001,0.01,0.1,1]
plt.xscale('log')
plt.xlim(10^-6,1.1) 
plt.xticks(y, labels)

但是我希望标签的格式为 10^-5, 10^-4, 10^-3, 10^-2, 10^-1, 1 而不是 1e-05, 0.0001, 0,001, 0,01, 0.1, 1

你需要这个FormatStrFormatter('%.2e')

因为你没有post你的整个脚本我只能给你看一个例子:

如果我们从 matplolib

中获取此演示

只需将 majorFormatter = FormatStrFormatter('%d') 更改为我之前向您展示的内容,您就会看到

您只需将主轴重新格式化为:

ax.xaxis.set_major_formatter(FormatStrFormatter('%.2e'))