使用Bokeh禁用坐标轴上的科学计数法

25

如何在Bokeh中禁用坐标轴上数字的科学计数法输出?例如,我想显示400000而不是4.00e+5。

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

4个回答

24

您可以使用以下方法禁用科学计数法:

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

3
上面的代码实际上是在垂直y轴上禁用它。如果您想在线图的水平x轴上禁用科学计数法,请使用:fig.below[0].formatter.use_scientific = False - Contango
代码和我的上面的注释适用于截至2019年1月1日(v1.0.3)的最新版本Bokeh。 - Contango

4

我试图关闭对数轴上的科学计数法,但以上答案并不适用于我。

我发现了这个链接: python bokeh plot如何格式化坐标轴显示

按照此方法,以下代码对我有用:

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)


4
请注意,从Bokeh v0.9.1开始,由于Charts接口的更改,Marek的答案将不再适用。以下代码(来自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

2
在Bokeh中禁用科学计数法输出,请使用您所使用的格式化器use_scientific属性。
您可以在此处找到有关use_scientific属性的更多信息: 示例(最初来自 Bokeh问题讨论):
from bokeh.models import Axis
yaxis = bar.chart.plot.select(dict(type=Axis, layout="left"))[0]
yaxis.formatter.use_scientific = False
bar.chart.show()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接