11

y 轴刻度似乎正在格式化数字,例如 500000000 到 5.000e+8。有没有办法控制显示,使其显示为 500000000?

使用 python 2.7,散景 0.5.2

我在散景教程页面尝试时间序列示例

本教程将“Adj Close”与“Date”绘制成图,但我使用“Volume”对“Date”进行绘制

4

2 回答 2

19

您还可以使用下面玩具图中使用的 NumeralTickFormatter。此处列出了替代“00”的其他可能值。

import pandas as pd
import numpy as np
from bokeh.plotting import figure, output_file, show
from bokeh.models import NumeralTickFormatter

df = pd.DataFrame(np.random.randint(0, 90000000000, (10,1)), columns=['my_int'])
p = figure(plot_width=700, plot_height=280, y_range=[0,100000000000])
output_file("toy_plot_with_commas")

for index, record in df.iterrows():
    p.rect([index], [record['my_int']/2], 0.8, [record['my_int']], fill_color="red", line_color="black")

p.yaxis.formatter=NumeralTickFormatter(format="00")
show(p)
于 2015-03-26T00:47:15.970 回答
12

您必须将选项添加p.left[0].formatter.use_scientific = False到您的代码中。在时间序列教程中,它将是:

p1 = figure(title="Stocks")
p1.line(
    AAPL['Date'],
    AAPL['Adj Close'],
    color='#A6CEE3',
    legend='AAPL',
)

p1.left[0].formatter.use_scientific = False # <---- This forces showing 500000000 instead of 5.000e+8 as you want

show(VBox(p1, p2))
于 2015-01-19T22:18:49.377 回答