【发布时间】:2020-04-14 23:06:25
【问题描述】:
您好,我想知道您如何将图形的 y 轴设置为百万,因此它不会显示 5e7,而是会在同一位置显示 50。谢谢
【问题讨论】:
标签: matplotlib plot axis ticker
您好,我想知道您如何将图形的 y 轴设置为百万,因此它不会显示 5e7,而是会在同一位置显示 50。谢谢
【问题讨论】:
标签: matplotlib plot axis ticker
您可以使用tick formatters 显示以百万为单位的数字,如下所示
import numpy as np
import matplotlib.ticker as ticker
@ticker.FuncFormatter
def million_formatter(x, pos):
return "%.1f M" % (x/1E6)
x = np.arange(1E7,5E7,0.5E7)
y = x
fig, ax = plt.subplots()
ax.plot(x,y)
ax.xaxis.set_major_formatter(million_formatter)
ax.yaxis.set_major_formatter(million_formatter)
ax.set_xlabel('X in millions')
ax.set_ylabel('Y in millions')
plt.xticks(rotation='45')
plt.show
导致
【讨论】: