2017-06-17 33 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' –