2016-02-03 119 views
0

我想将我的刻度格式化为一定数量的有效数字,并删除自动偏移量。对于后者,我使用https://stackoverflow.com/a/6654046/1021819,和前我会用https://stackoverflow.com/a/25750438/1021819,即matplotlib:不带偏移的格式轴刻度

y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) 
ax.yaxis.set_major_formatter(y_formatter) 

ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2e')) 

如何结合FormatStrFormatter和useOffset语法?

回答

1

FormatStrFormatter不使用偏移量,所以通过使用第二种格式,您将不会有偏移量。

比较两个次要情节在这个例子中

import matplotlib.pyplot as plt 
import matplotlib.ticker as mtick 
import numpy as np 

fig,(ax1,ax2)=plt.subplots(2) 

ax1.plot(np.arange(10000,10010,1)) 

ax2.plot(np.arange(10000,10010,1)) 
ax2.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.4e')) 

plt.show() 

enter image description here

+0

谢谢!扮演魔鬼的拥护者,如果我想在这个计划下得到抵消,该怎么办? – jtlz2