假设我有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。
这将决定初始缩放。如果您像文档中修改后的示例那样缩小,则其余数据仍将被绘制:
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)