我想将我的刻度格式化为一定数量的有效数字,并删除自动偏移量。对于后者,我使用的是https://stackoverflow.com/a/6654046/1021819,对于前者,我会使用https://stackoverflow.com/a/25750438/1021819,即
var test1,test2,test3;
Object.prototype.getInfo = function(){
return this.firstName + " - " + this.lastName;
}
function test1(){
this.firstName = "ham";
}
test2.prototype = test1;
function test2(){
this.lastName = "bam";
}
test3.prototype = test2;
function test3(){
return this.getInfo();
}
test1(); // at this level firstName property is available
test2(); // at this level firstName,lastName properties are available
test3(); // returns 'ham - bam' because the main prototype Object has the method getInfo and we have firstName,lastName from the previous prototypes.
和
y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
ax.yaxis.set_major_formatter(y_formatter)
如何组合FormatStrFormatter和useOffset语法?
答案 0 :(得分:2)
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()