[英]pandas plot timeseries color per id of the individual time series
我目前獲得以下情節:
但是,我不想繪制 2 個不相關的獨立時間序列,而是想為每個 device_id 繪制不同顏色的 metrik_0 列。
import pandas as pd
from pandas import Timestamp
d = pd.DataFrame({'metrik_0': {Timestamp('2020-01-01 00:00:00'): -0.5161200349325471,
Timestamp('2020-01-01 01:00:00'): 0.6404118012330947,
Timestamp('2020-01-01 02:00:00'): -1.0127867504877557,
Timestamp('2020-01-01 03:00:00'): 0.25828987625529976,
Timestamp('2020-01-01 04:00:00'): -2.486778084008076,
Timestamp('2020-01-01 05:00:00'): -0.30695039872663826,
Timestamp('2020-01-01 06:00:00'): -0.6570670310316116,
Timestamp('2020-01-01 07:00:00'): 0.3274964731894147,
Timestamp('2020-01-01 08:00:00'): -0.8624113311084097,
Timestamp('2020-01-01 09:00:00'): 1.0832911260447902},
'device_id': {Timestamp('2020-01-01 00:00:00'): 9,
Timestamp('2020-01-01 01:00:00'): 1,
Timestamp('2020-01-01 02:00:00'): 1,
Timestamp('2020-01-01 03:00:00'): 9,
Timestamp('2020-01-01 04:00:00'): 9,
Timestamp('2020-01-01 05:00:00'): 9,
Timestamp('2020-01-01 06:00:00'): 9,
Timestamp('2020-01-01 07:00:00'): 1,
Timestamp('2020-01-01 08:00:00'): 1,
Timestamp('2020-01-01 09:00:00'): 9}})
d.plot()
使用seaborn時,以下內容將起作用。
import seaborn as sns; sns.set()
d['device_id'] = d['device_id'].astype(str)
#display(d.head())
sns.lineplot(x='index', y='metrik_0', style='device_id', hue='device_id', data=d)
這可以原生地包含在 Pandas 的 plot 調用中嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.