简体   繁体   English

在散景上仅显示Y轴的一部分

[英]Display only part of Y-axis on Bokeh

Using Bokeh 0.8.1, how can i display a long timeserie, but start 'zoomed-in' on one part, while keeping the rest of data available for scrolling ? 使用Bokeh 0.8.1,我如何显示较长的时间,但一方面开始“放大”,而其余数据仍可滚动?

For instance, considering the following time serie (IBM stock price since 1980), how could i get my chart to initially display only price since 01/01/2014 ? 例如,考虑以下时间序列(1980年以来的IBM股票价格),我如何才能使图表最初仅显示2014年1月1日以来的价格?

Example code : 示例代码:

import pandas as pd
import bokeh.plotting as bk
from bokeh.models import ColumnDataSource
bk.output_notebook()
TOOLS="pan,wheel_zoom,box_zoom,reset,save"

# Quandl data, too lazy to generate some random data
df = pd.read_csv('https://www.quandl.com/api/v1/datasets/GOOG/NYSE_IBM.csv')
df['Date'] = pd.to_datetime(df['Date'])
df = df[['Date', 'Close']]

#Generating a bokeh source
source = ColumnDataSource()
dtest = {}
for col in df:
    dtest[col] = df[col]

source = ColumnDataSource(data=dtest)

# plotting stuff !
p = bk.figure(title='title', tools=TOOLS,x_axis_type="datetime", plot_width=600, plot_height=300)
p.line(y='Close', x='Date', source=source)
bk.show(p)

outputs : 输出:

IBM

but i want to get this (which you can achieve with the box-zoom tool - but I'd like to immediately start like this) 但是我想得到这个(您可以使用box-zoom工具来实现-但我想立即像这样开始)

IBM

So, it looks (as of 0.8.1) that we need to add some more convenient ways to set ranges with datetime values. 因此,看起来(从0.8.1开始),我们需要添加一些更方便的方法来设置带有日期时间值的范围。 That said, although this is a bit ugly, it does currently work for me: 话虽如此,尽管这有点丑陋,但目前确实对我有用:

import time, datetime
x_range = (
    time.mktime(datetime.datetime(2014, 1, 1).timetuple())*1000,
    time.mktime(datetime.datetime(2016, 1, 1).timetuple())*1000
)
p = bk.figure(
    title='title', tools=TOOLS,x_axis_type="datetime",     
    plot_width=600, plot_height=300, x_range=x_range
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM