如何缩放到初始绘图/缩放的特定范围?

时间:2015-01-19 20:01:31

标签: python numpy anaconda bokeh

如果我有时间序列范围2015-01-01到2015-12-31并且我用散景绘制,但有没有办法我可以默认将它缩放到第一个月(然后我们可以滚动出来以后)?谢谢

1 个答案:

答案 0 :(得分:2)

您可以在figure()电话的最开始专门设置所需的范围...让我们在一个示例中看到它:

import numpy as np

from bokeh.sampledata.stocks import AAPL, FB, GOOG, IBM, MSFT
from bokeh.plotting import *

output_file("stocks.html", title="stocks.py example")

left_range = np.datetime64('2000-03-01')
right_range = np.datetime64('2006-03-01')

p1 = figure(x_axis_type = "datetime", x_range=[left_range, right_range])

p1.line(np.array(AAPL['date'], 'M64'), AAPL['adj_close'], color='#A6CEE3', legend='AAPL')
p1.line(np.array(FB['date'], 'M64'), FB['adj_close'], color='#1F78B4', legend='FB')
p1.line(np.array(GOOG['date'], 'M64'), GOOG['adj_close'], color='#B2DF8A', legend='GOOG')
p1.line(np.array(IBM['date'], 'M64'), IBM['adj_close'], color='#33A02C', legend='IBM')
p1.line(np.array(MSFT['date'], 'M64'), MSFT['adj_close'], color='#FB9A99', legend='MSFT')

p1.title = "Stock Closing Prices"
p1.grid.grid_line_alpha=0.3
p1.xaxis.axis_label = 'Date'
p1.yaxis.axis_label = 'Price'

show(p1) 

在这里,我只定义了范围的左右值:

p1 = figure(x_axis_type = "datetime", x_range=[left_range, right_range])

如果您需要更多帮助,请与我联系。