【问题标题】:Scientific Notation in matplotlib inline plots in jupyterjupyter中matplotlib内联图中的科学记数法
【发布时间】: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 matplotlibenter link description hereChange x axes scale in matplotlib 注意:如果我用import mpld3mpld3.enable_notebook() 注释掉这些行,那么它可以工作,但不能与情节交互......在jupyter 中绘制内联时,matplotlib 是否有一些特殊处理? 谢谢!

【问题讨论】:

  • 您能否分享一个完整的minimal reproducible example,以及显示当前输出的图像以解释哪里错了?
  • 感谢您的评论汤姆。我编辑了问题以包含一个示例。对不起,到目前为止“无线电沉默”。

标签: python matplotlib plot jupyter


【解决方案1】:

您可以使用set_yticklabels 来获得类似的输出。

ax = plt.gca()
ax.set_yticklabels(['10^-8','2*10^-8','3*10^-8','4*10^-8'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 2017-09-05
    • 2013-06-27
    相关资源
    最近更新 更多