使用Bokeh禁用坐标轴科学计数法
如何在bokeh中关闭数字的科学计数法显示?
比如,我想显示400000,而不是4.00e+5。
在mpl中,可以用这个代码:ax.get_xaxis().get_major_formatter().set_scientific(False)
4 个回答
4
请注意,从Bokeh v0.9.1版本开始,Marek的回答将不再有效,因为Charts
的接口发生了变化。以下代码(来自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
要在Bokeh中关闭科学计数法输出,你可以使用use_scientific
这个属性,它是你所用的格式化器的一部分。
关于use_scientific
这个属性的更多信息,你可以在这里找到:
- 在Bokeh代码中对这个属性的描述:BasicTickFormatter类(第28行)
- 关于
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()
6
我想关闭对数轴的科学计数法,但上面的回答对我没用。
我找到这个链接: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)
25
你可以用这个方法来关闭科学计数法:
fig = plt.figure(title='xxx', x_axis_type='datetime')
fig.left[0].formatter.use_scientific = False