无法使用散景图 'desired_num_ticks'。抛出的错误是“'NoneType' 对象没有属性 'desired_num_ticks'”

Unable to use Bokeh plot's 'desired_num_ticks'. Error thrown is " 'NoneType' object has no attribute 'desired_num_ticks' "

根据这篇文档,我了解到 'desired_num_ticks' 并未被弃用,它需要一个整数。

https://docs.bokeh.org/en/latest/docs/reference/models/tickers.html

但我得到以下情节的错误。 (请注意,当我评论'f.ygrid[0].ticker.desired_num_ticks = 1'时,一切正常,我得到了散景图)

print(df) # the data that i'm using
                       Start                        End
0  2020-06-14 11:30:05.940200 2020-06-14 11:30:06.244248
1  2020-06-14 11:30:06.276542 2020-06-14 11:30:06.371198
2  2020-06-14 11:30:06.516061 2020-06-14 11:30:06.547580
3  2020-06-14 11:30:06.579995 2020-06-14 11:30:06.612236
4  2020-06-14 11:30:06.644278 2020-06-14 11:30:06.676330
5  2020-06-14 11:30:10.243353 2020-06-14 11:30:10.755898
from detection1dot2 import df     # import the dataframe
from bokeh.plotting import figure, show, output_file

f=figure(x_axis_type='datetime', height=500, width=500, sizing_mode="stretch_width", title='Motion Graph')
f.yaxis.minor_tick_line_color = None
f.ygrid[0].ticker.desired_num_ticks = 1

f.quad(left=df["Start"], right=df["End"], bottom=0, top=1)
output_file("motion.html")

当我 运行 脚本时,出现以下错误。


   f.ygrid[0].ticker.desired_num_ticks = 1
AttributeError: 'NoneType' object has no attribute 'desired_num_ticks'

在您的情况下,网格没有明确设置的代码。我认为它没有正确记录 - Grid.ticker 用于覆盖默认情况下网格使用的相应轴自动收报机。所以如果你有一个 Y 轴,你可以只使用

f.yaxis.ticker.desired_num_ticks = 1

相反。

而不是

f.ygrid[0].ticker.desired_num_ticks = 1

使用

f.ygrid.ticker = [0,1] # pass a list of desired ticks

它会起作用