【发布时间】:2017-11-10 14:05:37
【问题描述】:
我正在绘制 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 是否有一些特殊处理?
谢谢!
【问题讨论】:
-
您能否分享一个完整的minimal reproducible example,以及显示当前输出的图像以解释哪里错了?
-
感谢您的评论汤姆。我编辑了问题以包含一个示例。对不起,到目前为止“无线电沉默”。
标签: python matplotlib plot jupyter