我绘制的是10^-8阶的值,我希望我在jupyter中的内联绘图以那个(科学)表示法输出yaxis记号。我试过了:
plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E'))以及
plt.gca().yaxis.get_major_formatter().set_powerlimits((0, -10))和
plt.ticklabel_format(style='sci')但似乎什么都不起作用。我做错了什么?我有下面的例子:
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()
import matplotlib.ticker as mtick
a=5*10**-8
b=3*10**-8
x=np.arange(0,10,0.01)
y=a*x+b
plt.figure(figsize=(12,5))
plt.subplot(1,2,1)
plt.plot(x,y)
# plt.ticklabel_format(style='sci')
# plt.gca().yaxis.get_major_formatter().set_powerlimits((0, -10))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0e'))
plt.show()任何指针都会有帮助,因为我找不到任何关于这个的东西,除了ticks format of an axis in matplotlib,enter link description here或Change x axes scale in matplotlib注意:如果我用import mpld3和mpld3.enable_notebook()注释掉这些行,那么它可以工作,但不能与绘图交互……在jupyter中进行内联绘图时,matplotlib有什么特殊处理吗?谢谢!
发布于 2017-11-10 22:39:20
您可以使用set_yticklabels来获得类似的输出。
ax = plt.gca()
ax.set_yticklabels(['10^-8','2*10^-8','3*10^-8','4*10^-8'])https://stackoverflow.com/questions/47224557
复制相似问题