如何从对数对数图中删除科学记数法?
How to remove scientific notation from a log-log plot?
我希望 y 轴只显示数字 100、200 和 300,而不是科学记数法。有什么想法吗?
Current plot
简化代码:
from matplotlib import pyplot as plt
import numpy as np
x = np.logspace(2, 6, 20)
y = np.logspace(np.log10(60), np.log10(300), 20)
plt.scatter(x, y[::-1])
plt.xscale('log')
plt.yscale('log')
plt.show()
主要和次要定位符决定刻度线的位置。标准位置通过 AutoLocator
设置。 NullLocator
删除它们。 MultipleLocator(x)
每 x
.
的倍数显示价格变动
对于 y 轴,设置标准刻度位置显示顶部的刻度彼此更接近,这由对数刻度决定。然而,由于范围很大,对 x 轴做同样的事情会使它们靠得太近。因此,对于 x 轴,由 LogLocator
确定的位置可以保持不变。
格式化程序控制刻度的显示方式。 ScalarFormatter
设置默认方式。有一个选项 scilimits
可以确定应该使用科学记数法的值范围。由于 1.000.000 通常显示为 1e6
,设置 scilimits=(-6,9)
可以避免这种情况。
from matplotlib import pyplot as plt
from matplotlib import ticker
import numpy as np
x = np.logspace(2, 6, 20)
y = np.logspace(np.log10(60), np.log10(300), 20)
plt.scatter(x, y[::-1])
plt.xscale('log')
plt.yscale('log')
ax = plt.gca()
# ax.xaxis.set_major_locator(ticker.AutoLocator())
ax.xaxis.set_minor_locator(ticker.NullLocator()) # no minor ticks
ax.xaxis.set_major_formatter(ticker.ScalarFormatter()) # set regular formatting
# ax.yaxis.set_major_locator(ticker.AutoLocator()) # major y tick positions in a regular way
ax.yaxis.set_major_locator(ticker.MultipleLocator(100)) # major y tick positions every 100
ax.yaxis.set_minor_locator(ticker.NullLocator()) # no minor ticks
ax.yaxis.set_major_formatter(ticker.ScalarFormatter()) # set regular formatting
ax.ticklabel_format(style='sci', scilimits=(-6, 9)) # disable scientific notation
plt.show()
我希望 y 轴只显示数字 100、200 和 300,而不是科学记数法。有什么想法吗?
Current plot
简化代码:
from matplotlib import pyplot as plt
import numpy as np
x = np.logspace(2, 6, 20)
y = np.logspace(np.log10(60), np.log10(300), 20)
plt.scatter(x, y[::-1])
plt.xscale('log')
plt.yscale('log')
plt.show()
主要和次要定位符决定刻度线的位置。标准位置通过 AutoLocator
设置。 NullLocator
删除它们。 MultipleLocator(x)
每 x
.
对于 y 轴,设置标准刻度位置显示顶部的刻度彼此更接近,这由对数刻度决定。然而,由于范围很大,对 x 轴做同样的事情会使它们靠得太近。因此,对于 x 轴,由 LogLocator
确定的位置可以保持不变。
格式化程序控制刻度的显示方式。 ScalarFormatter
设置默认方式。有一个选项 scilimits
可以确定应该使用科学记数法的值范围。由于 1.000.000 通常显示为 1e6
,设置 scilimits=(-6,9)
可以避免这种情况。
from matplotlib import pyplot as plt
from matplotlib import ticker
import numpy as np
x = np.logspace(2, 6, 20)
y = np.logspace(np.log10(60), np.log10(300), 20)
plt.scatter(x, y[::-1])
plt.xscale('log')
plt.yscale('log')
ax = plt.gca()
# ax.xaxis.set_major_locator(ticker.AutoLocator())
ax.xaxis.set_minor_locator(ticker.NullLocator()) # no minor ticks
ax.xaxis.set_major_formatter(ticker.ScalarFormatter()) # set regular formatting
# ax.yaxis.set_major_locator(ticker.AutoLocator()) # major y tick positions in a regular way
ax.yaxis.set_major_locator(ticker.MultipleLocator(100)) # major y tick positions every 100
ax.yaxis.set_minor_locator(ticker.NullLocator()) # no minor ticks
ax.yaxis.set_major_formatter(ticker.ScalarFormatter()) # set regular formatting
ax.ticklabel_format(style='sci', scilimits=(-6, 9)) # disable scientific notation
plt.show()