Python Matplotlib在符号图中禁用指数表示法
假设我有以下代码Python Matplotlib在符号图中禁用指数表示法,python,matplotlib,scientific-notation,Python,Matplotlib,Scientific Notation,假设我有以下代码 import matplotlib.pyplot as plt plt.figure() plt.semilogy([0,1],[20,90]) plt.show() 这将创建下图: 我想禁用y轴上的科学记数法(因此我希望使用20、30、40、60,而不是2x10^1等) 我已经看过线程了,我试着添加 import matplotlib.ticker plt.gca().get_yaxis().set_major_formatter(matplotlib.ticker.Sc
import matplotlib.pyplot as plt
plt.figure()
plt.semilogy([0,1],[20,90])
plt.show()
这将创建下图:
我想禁用y轴上的科学记数法(因此我希望使用20、30、40、60,而不是2x10^1等)
我已经看过线程了,我试着添加
import matplotlib.ticker
plt.gca().get_yaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
plt.gca().get_yaxis().get_major_formatter().set_scientific(False)
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
但这并不影响结果,我使用的是python 3.5.3和matplotlib 2.1.0。我遗漏了什么?因为y轴上的刻度在不到十年的时间内,所以它们是次要刻度,而不是主要刻度。因此,您需要将次要格式化程序设置为
ScalarFormatter
plt.gca().yaxis.set_minor_formatter(matplotlib.ticker.ScalarFormatter())
Aaaaah,这就是我所缺少的。非常感谢!:)
import matplotlib.pyplot as plt
import matplotlib.ticker
plt.figure()
plt.semilogy([0,1],[20,90])
plt.gca().yaxis.set_minor_formatter(matplotlib.ticker.ScalarFormatter())
plt.show()