[英]Seaborn / Matplotlib: How to repress scientific notation in factorplot y-axis
[英]Matplotlib: setting the Y-axis to none scientific notation AFTER changing the Y-axis to log scale
我有一个简单的图形与对象axs
对于轴。 在我将 Y 轴更改为对数刻度之前,格式只是常规数字。
在我使用以下方法将 Y 轴更改为对数刻度后: axs.set_yscale('log')
... 然后尝试将数字改回
axs.set_yticklabels(['{:,}'.format(int(x)) for x in axs.get_yticks().tolist()])
它不起作用......标签仍然保留在科学记数法中。
我只想找回常规数字。
我正在使用:
fig = plt.figure(figsize=(30, 15))
axs = fig.add_subplot(1, 1, 1)
axs.plot()
如前所述,您可以在此处设置ScalarFormatter
以省略科学记数法。 还需要.set_scientific(False)
来抑制大数字的科学记数法。
如果您正在处理负幂axs.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '{:g}'.format(y)))
您可能需要axs.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '{:g}'.format(y)))
。
from matplotlib import pyplot as plt
from matplotlib.ticker import ScalarFormatter
fig = plt.figure(figsize=(30, 15))
axs = fig.add_subplot(1, 1, 1)
axs.plot()
axs.set_ylim(100000, 100000000)
axs.set_yscale('log')
formatter = ScalarFormatter()
formatter.set_scientific(False)
axs.yaxis.set_major_formatter(formatter)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.