【发布时间】:2018-06-10 18:59:43
【问题描述】:
我有一个提供散景图的网络应用程序(使用散景 v0.12.7)。 x 轴是日期时间,显示用户定义的天数(日期范围默认为 31 天)。在 Bokeh 中未定义任何刻度参数时,主要刻度数默认为 5,如此处的实时 Web 应用程序所示:
https://btac-web-plots.herokuapp.com/avyview?style=snowpacktracker
我想在主要刻度之间显示每天的次要刻度。我尝试了以下方法,它允许任何日期范围长度,并每 5 天指定一次主要刻度(start 和 end 是 Pandas 日期时间索引):
num_days = ((end - start) / np.timedelta64(1, 'D')).astype(int)
fig.xaxis.ticker = DaysTicker(
days = np.arange(1, num_days, 5),
num_minor_ticks = 4
)
这会每 5 天正确显示一次主要刻度,但不显示次要刻度。另一种可能的解决方案可能是每天绘制主要刻度,然后将刻度标签设置为不可见,除了每 5 天(不确定如何实现...)。
在这些图上显示每日小刻度的最佳方法是什么?
这是我的一段绘图代码(包括DaysTicker),以第一个面板为例:
fig = figure(
title="New Snow, SWE, Snow Depth, and Settlement",
name="newsnow_extra_fig",
x_axis_type="datetime",
y_axis_label='HN24 / SWE (in)',
width=width, height=height2,
tools=tools,
toolbar_sticky=False,
logo=None
)
fig.y_range = Range1d(-12, 30)
fig.extra_y_ranges = {"Depth": Range1d(start=-72, end=180)}
fig.add_layout(LinearAxis(y_range_name="Depth", axis_label='HS (in)' ), 'right')
fig.yaxis.axis_label_standoff = 5
num_days = ((end - start) / np.timedelta64(1, 'D')).astype(int)
fig.xaxis.ticker = DaysTicker(
days=np.arange(1,num_days,5),
num_minor_ticks=4
)
newcds, newcds_sums = create_newsnow_extra_cds(df, 'mid', start, end)
dline = fig.line(source=newcds,
x='Date', y='depth',
line_color="blue", line_width=2, line_alpha=0.5,
legend="snow depth (HS)", name="depthline",
y_range_name='Depth',
)
nsbars = fig.vbar(source=newcds,
x='newsnow_x', width=WIDTH, bottom=0, top='newsnow',
color="blue", alpha=0.9, legend='new snow (HN24)', name='nsbars'
)
swebars = fig.vbar(source=newcds,
x='swex10_x', width=WIDTH, bottom=0, top='swex10',
color="blue", alpha=0.3, legend='SWE x 10', name='swebars'
)
settlebars = fig.vbar(source=newcds,
x='Date', width=WIDTH*2.0, bottom='settle', top=0,
color="orange", alpha=0.75,
name="settlebars", legend="settlement"
)
【问题讨论】: