2016-11-16 62 views
1

嗨我想創建一個時間序列圖使用散景。 我看起來像這樣的數據,2列一個是時間戳,它實際上是當前時間,值和提供該值的傳感器時間序列圖與散景

時間|值|傳感器

2011-05-03 17:45:35.177000 | 213.130005 | A

2011-05-03 17:45:36.177000 | 208.83 | B

2011-05-03 17:45:36.277000 | 212.629993 | C

2011-05-03 17:45:45.317000 | 211.719999 | A

2011-05-03 17:45:45.577000 | 203.549999 | B

2011-05-03 17:45:48.177000 | 201.199999 | B

2011-05-03 17:45:55.175000 | 199.439999 | ç

我完全新的背景虛化 ,我不知道我怎麼可以將用戶的背景虛化來渲染每個傳感器的數據獨立地在圖表上,沿東西this

  • 做線我需要熊貓,如示例中所示?
  • 我如何使用熊貓來解析時間戳列,從例子中,我只看到pandas.parse_dates

回答

1

1)你不使用熊貓,但是這條路線使得它更容易。
2)您可以只用大熊貓to_datetime()功能(pandas docs reference

from bokeh.plotting import figure, show 
from bokeh.models import DatetimeTickFormatter 
import pandas as pd 
import csv 

d = pd.read_csv("SO.txt", delimiter="|") 
# Strip whitespace from spacing in column headers 
d.columns = [val.strip() for val in d.columns.values] 
d["Time"] = pd.to_datetime(d["Time"], yearfirst=True) 

unique_sensors = d["Sensor"].unique() 
c = ["red","blue","green"] 

fig = figure(x_axis_label="Time (Seconds)", y_axis_label="Value", title="Sample") 

# Draw a line for each unique sensor value 
for i, s in enumerate(unique_sensors): 
    sdf = d.loc[d["Sensor"]==s] 
    fig.line(x=sdf["Time"], y=sdf["Value"], legend=s, line_color=c[i], line_width=3.0) 
fig.xaxis.formatter = DatetimeTickFormatter(hours=["%b %d %Y"], 
              days=["%b %d %Y"], 
              months=["%b %d %Y"], 
              years=["%b %d %Y"]) 
show(fig) 

解析時間功能,但顯然,你需要你的彩色地圖縮放到您的問題,所以我建議看在背景虛化調色板(bokeh docs reference