【问题标题】:Disable scientific notation on axes using Bokeh使用 Bokeh 禁用轴上的科学记数法
【发布时间】:2014-08-23 12:28:31
【问题描述】:

如何禁用散景轴上数字的科学输出? 例如,我想要 400000 而不是 4.00e+5

在 mpl 中:ax.get_xaxis().get_major_formatter().set_scientific(False)

【问题讨论】:

    标签: python plot bokeh


    【解决方案1】:

    你可以用这个禁用科学记数法:

    fig = plt.figure(title='xxx', x_axis_type='datetime')
    fig.left[0].formatter.use_scientific = False
    

    【讨论】:

    • 上面的代码实际上在垂直 y 轴上禁用了它。如果您想在水平 x 轴上禁用线图的科学记数法,请使用:fig.below[0].formatter.use_scientific = False
    • 代码和我上面的评论适用于截至 2019-01-01 (v1.0.3) 的最新版本的 Bokeh。
    【解决方案2】:

    要在 Bokeh 中禁用 科学输出,请使用您使用的 formatteruse_scientific 属性。

    您可以在此处找到有关use_scientific 属性的更多信息:

    示例(原文来自Bokeh issues discussion):

    from bokeh.models import Axis
    yaxis = bar.chart.plot.select(dict(type=Axis, layout="left"))[0]
    yaxis.formatter.use_scientific = False
    bar.chart.show()
    

    【讨论】:

      【解决方案3】:

      请注意,从 Bokeh v0.9.1 开始,由于 Charts 的界面发生变化,Marek 的回答将不再有效。以下代码 (from GitHub) 是如何在高级图表中关闭科学记数法的全功能示例。

      from bokeh.embed import components
      from bokeh.models import Axis
      from bokeh.charts import Bar
      data = {"y": [6, 7, 2, 4, 5], "z": [1, 5, 12, 4, 2]}
      bar = Bar(data)
      yaxis = bar.select(dict(type=Axis, layout="left"))[0]
      yaxis.formatter.use_scientific = False
      script, div = components(bar)
      print(script)
      print(div)
      

      重点是:

      yaxis = bar.select(dict(type=Axis, layout="left"))[0]
      yaxis.formatter.use_scientific = False
      

      【讨论】:

        【解决方案4】:

        我试图关闭对数轴的科学记数法,上述答案对我不起作用。

        我发现了这个:python bokeh plot how to format axis display

        本着这种精神,这对我有用:

        from bokeh.models import BasicTickFormatter
        
        fig = plt.figure(title='xxx', x_axis_type='datetime',y_axis_type='log')
        fig.yaxis.formatter = BasicTickFormatter(use_scientific=False)
        
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-05-01
          • 2011-08-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多