散景从一开始就显示放大图

bokeh show zoomed-in plot from start

假设我绘制了 50 年的数据

import pandas as pd
from bokeh.charts import TimeSeries
df = pd.util.testing.makeTimeDataFrame(12500)
p = TimeSeries(df, tools = 'xwheel_zoom,reset')

当我打开html文件时,它显示了整个数据然后我可以放大。有没有办法指定当我打开html文件时,它只显示说去年的数据?

您可以按照说明设置 x_range in the docs

这将决定初始缩放。如果您像文档中的这个修改后的示例一样缩小,其余数据仍将被绘制:

from bokeh.plotting import figure, output_file, show
from bokeh.models import Range1d

output_file("title.html")

# create a new plot with a range set with a tuple
p = figure(plot_width=400, plot_height=400, x_range=(0, 20))

# set a range using a Range1d
p.y_range = Range1d(0, 15)

p.circle([1, 2, 3, 4, 5, 25], [2, 5, 8, 2, 7, 50], size=10)

show(p)

由于最初的问题询问的是日期范围轴,因此可能需要更多说明。也许这会奏效。

这将在 2018 年 6 月 12 日左右放大。

from bokeh.plotting import figure, output_file, show
from bokeh.models import Range1d

output_file("title.html")

date_times = pd.date_range('2018-06-11', periods=4, freq='D')
# set min and max date times for plotting
x_min = date_times[0]
x_max = date_times[-1]

# create a new plot with a range set with a tuple
p = figure(plot_width=400, 
           plot_height=400, 
           y_axis_type="linear",
           x_axis_type="datetime", 
           x_range=(x_min, x_max))

# set a range using a Range1d
p.y_range = Range1d(0, 15)

p.circle([1, 2, 3, 4, 5, 25], [2, 5, 8, 2, 7, 50], size=10)

show(p)