Python Matplotlib.pyplot:强制指数轴标签表示法
在matplotlib.pyplot创建的绘图中,如何强制以指数表示法显示轴标签?对于<1e-6的值,这似乎是自动完成的,但是对于5e-6,我得到“0.000005”。对于这个范围,我更愿意将其显示为“5e-6”。似乎您应该能够设置轴的功率限制。(未测试代码)Python Matplotlib.pyplot:强制指数轴标签表示法,python,matplotlib,Python,Matplotlib,在matplotlib.pyplot创建的绘图中,如何强制以指数表示法显示轴标签?对于
#将限制设置为x<10^1和x>10^-1
#(重叠,因此包罗万象,希望如此)
gca().get_yaxis().get_major_formatter().set_powerlimits((0,0))
%e
是指数级的,你可以做得更好,只需在gca()上调用set\u powerlimits
。get\u major\u formatter()
@tcaswell:很好,谢谢。@voithos:我不得不使用gca().yaxis.get\u major\u formatter()。set\u powerlimits(-1,1))
。是否有一种(优雅的)方法可以一次性将更改应用于两个轴@你是怎么做到的?在没有参数的情况下调用set\u powerlimits
会出错。@gandi2223抱歉,删除了一个层。优雅的方法是两者兼而有之。如果要更改默认值,请在matplotlib.rc
# Set limits to x < 10^1 and x > 10^-1
# (overlapping, thus all inclusive, hopefully)
gca().get_yaxis().get_major_formatter().set_powerlimits((0, 0))