2017-06-17 66 views
0

缩放我是相当新的背景虚化,努力实现以下几点:动态指标,而在Python散景

我有包含格式DD-MM-YYYY日期行的数据集。 计算日期并绘制。 放大时,我想让Bokeh显示个人日期(已工作)。 缩小时,我只想要使用Bokeh来显示月份(或甚至进一步缩小的年份)。知道索引变得非常混乱,因为个别日期越来越近,缩小得越多。

有没有办法让Bokeh根据放大或缩小的距离来改变索引中显示的内容?

这里是我的代码:

import pandas as pd 
from bokeh.charts import TimeSeries 
from bokeh.io import output_file, show, gridplot 

transactionssent = dict(pd.melt(df,value_vars=['datesent']).groupby('value').size()) 
transactionssent2 = pd.DataFrame.from_dict(transactionssent, orient= 'index') 
transactionssent2.columns = ['Amount'] 
transactionssent2.index.rename('Date sent', inplace= True) 

ts = TimeSeries(transactionssent2, x='index', y='Amount') 
ts.xaxis.axis_label = 'Date sent' 

如果有人知道请点我在正确的方向。

感谢和问候, 斯特凡

回答

0

你所描述什么,你想要什么已经听起来像内置的日期时间轴的标准行为。所以,我的猜测是TimeSeries将您的日期视为字符串/分类值,这可以解释为什么您没有看到标准日期时间轴缩放。

我应该补充说明bokeh.charts(包括TimeSeries)最近已被移除到一个单独的项目,并且也被称为有问题。我实际上不鼓励它在这个时候使用。幸运的是,使用bokeh.plotting API绘制时间序列也很容易,该API是稳定的,经过良好测试和记录的,并且被广泛使用。

下面是一个例子来说明:

import datetime 
import numpy as np 

from bokeh.io import show, output_file 
from bokeh.plotting import figure 

# some fake data just for this example, Pandas columns work fine too 
start = datetime.datetime(2017, 1, 1) 
x = np.array([start + datetime.timedelta(hours=i) for i in range(800)]) 
y = np.sin(np.linspace(0, 2, len(x))) + 0.05 * np.random.random(len(x)) 

p = figure(x_axis_type="datetime") 
p.line(x, y) 

output_file("stocks.html") 

show(p) 

其轴线看起来像这样第一次显示时: enter image description here


enter image description here

但是,像这样在放大时

你还可以通过设置p.xaxis[0].formatter上的各种属性来进一步定制日期格式化程序。有关可用属性的详细信息,请参阅参考指南:

http://bokeh.pydata.org/en/latest/docs/reference/models/formatters.html#bokeh.models.formatters.DatetimeTickFormatter

+0

谢谢!这绝对解决了我的问题!重新格式化我的数据(我使用德语风格的日期)后,我的图形看起来更好用'bokeh.plotting.figure' –