2016-08-09 58 views
0

我DF1熱圖可視化

df1.info() 


<class 'pandas.core.frame.DataFrame'> 
RangeIndex: 38840 entries, 0 to 38839 
Data columns (total 7 columns): 
TIMESTAMP     38840 non-null datetime64[ns] 
ACT_TIME_AERATEUR_1_F1 38696 non-null float64 
ACT_TIME_AERATEUR_1_F3 38697 non-null float64 
ACT_TIME_AERATEUR_1_F5 38695 non-null float64 
ACT_TIME_AERATEUR_1_F6 38695 non-null float64 
ACT_TIME_AERATEUR_1_F7 38693 non-null float64 
ACT_TIME_AERATEUR_1_F8 38696 non-null float64 
dtypes: datetime64[ns](1), float64(6) 
memory usage: 2.1 MB 

一個數據幀,看起來像這樣:

TIMESTAMP ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3 ACT_TIME_AERATEUR_1_F5 ACT_TIME_AERATEUR_1_F6 ACT_TIME_AERATEUR_1_F7 
ACT_TIME_AERATEUR_1_F8 
2015-08-01 05:10:00 100 100 100 100 100 100 
2015-08-01 05:20:00 100 100 100 100 100 100 
2015-08-01 05:30:00 100 100 100 100 100 100 
2015-08-01 05:40:00 100 100 100 100 100 100 

我嘗試創建seaborn熱圖想象這是兩個日期之間(例如在此之間的數據'2015年8月1日23點10分零零秒' 和 '2015年8月2日02:00:00'): 我這樣做:

df1['TIMESTAMP']= pd.to_datetime(df_no_missing['TIMESTAMP'], '%d-%m-%y %H:%M:%S') 
df1['date'] = df_no_missing['TIMESTAMP'].dt.date 
df1['time'] = df_no_missing['TIMESTAMP'].dt.time 
date_debut = pd.to_datetime('2015-08-01 23:10:00') 
date_fin = pd.to_datetime('2015-08-02 02:00:00') 

df1 = df1[(df1['TIMESTAMP'] >= date_debut) & (df1['TIMESTAMP'] < date_fin)] 

sns.heatmap(df1.iloc[:,1:6:],annot=True, linewidths=.5) 

我有一個熱圖像附

enter image description here

我現在的問題是如何能夠通過我的時間戳及其相應值替換熱圖地圖(145 ... 161)左側的數量(2015年-08-01 5點10分00秒,2015年8月1日五時二十分00秒,2015年8月1日5時30分零零秒,...)

謝謝

最好成績

我嘗試進行修改:

df1.set_index("TIMESTAMP", inplace=1) 
sns.heatmap(df1.iloc[:, 1:6:], annot=True, linewidths=.5) 
ax = plt.gca() 
ax.set_yticklabels([i.strftime("%Y-%m-%d %H:%M:%S") for i in df1.TIMESTAMP], rotation=0) 

編輯

,但我得到的錯誤和警告:

C:\Users\Demonstrator\Anaconda3\lib\site-packages\ipykernel\__main__.py:2: 

SettingWithCopyWarning: 值要試圖從一個數據幀的一個切片的副本設置。 嘗試使用的.loc [row_indexer,col_indexer] =值代替

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy 
    from ipykernel import kernelapp as app 
C:\Users\Demonstrator\Anaconda3\lib\site-packages\ipykernel\__main__.py:3: 

SettingWithCopyWarning: 的值是試圖要在從數據幀切片的拷貝集。 嘗試使用的.loc [row_indexer,col_indexer] =值代替

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy 
    app.launch_new_instance() 
C:\Users\Demonstrator\Anaconda3\lib\site-packages\ipykernel\__main__.py:4: 

SettingWithCopyWarning: 的值是試圖要在從數據幀切片的拷貝集。 嘗試使用。LOC [row_indexer,col_indexer] =值代替

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy 




--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-129-cec498d88cac> in <module>() 
     9 
    10 #sns.heatmap(df1.iloc[:,1:6:],annot=True, linewidths=.5) 
---> 11 sns.heatmap(df1.iloc[:, 1:6:], annot=True, linewidths=.5) 
    12 ax = plt.gca() 
    13 ax.set_yticklabels([i.strftime("%Y-%m-%d %H:%M:%S") for i in df1.TIMESTAMP], rotation=0) 

C:\Users\Demonstrator\Anaconda3\lib\site-packages\seaborn\matrix.py in 

熱圖(數據,VMIN,VMAX,CMAP,中心,健壯,ANNOT,FMT,annot_kws, 線寬,linecolor,CBAR,cbar_kws,cbar_ax,正方形,斧, xticklabels,yticklabels,掩模,** kwargs) 483繪圖儀= _HeatMapper(數據,VMIN,VMAX,CMAP,中心,健壯,ANNOT,FMT, 484 annot_kws,CBAR,cbar_kws,xticklabels, - > 485 yticklabels ,mask) 487#在這裏添加pcolormesh kwargs

C:\Users\Demonstrator\Anaconda3\lib\site-packages\seaborn\matrix.py in 

初始化(個體經營,數據,最小值,VMAX,CMAP,中心,強大的,ANNOT,格式化,annot_kws,CBAR,cbar_kws,xticklabels,yticklabels,面罩) 165#確定好的默認值colormapping 166自._determine_cmap_params(plot_data,VMIN,VMAX, - > 167 CMAP,中心,魯棒) 169#理清註解

C:\Users\Demonstrator\Anaconda3\lib\site-packages\seaborn\matrix.py in 

_determine_cmap_params(個體,plot_data,VMIN,VMAX,CMAP,中心,健壯) 204 calc_data = plot_data.data [〜np.i snan(plot_data.data)] 如果vmin爲無: - > 206 vmin = np.percentile(calc_data,2)如果功能強大其他calc_data.min() 207 if vmax is None: 208 vmax = np。百分位數(calc_data,98)如果健壯其他calc_data.max()

C:\Users\Demonstrator\Anaconda3\lib\site-packages\numpy\core\_methods.py 

在_amin(一,軸,指出,keepdims) 28 DEF _amin(一,軸=無,OUT =無,keepdims = False): ---> 29 return umr_minimum(a,axis,None,out,keepdims) 31 def _sum(a,axis = None,dtype = None,out = None,keepdims = False):

ValueError: zero-size array to reduction operation minimum which has no identity 

@jeanrjc,看最後的圖像,還有一個問題:圖像太小且有右側兩個垂直線(規模)。我希望我'立即清除enter image description here

回答

0

這是因爲TIMESTAMP是不是你的指數,從sns.heatmap文檔字符串:

yticklabels:列表類似,int或布爾,可選 如果真,積數據幀的行名稱。如果爲False,則不要繪製 的行名稱。如果列表類似,請將這些替代標籤繪製爲標籤。如果是整數,則使用索引名稱,但僅繪製每個標籤的標籤。

行名是索引。

所以你可以設置相應的指標:

df1.set_index("TIMESTAMP", inplace=1) 

,並與您sns命令,它會工作幾乎罰款。問題是你會有一個醜陋的日期表示。

或者,你可以做的,而不是更改索引

import matplotlib.pyplot as plt 
import seaborn as sns 
import pandas as pd 
... 
... 
ax = sns.heatmap(df1.iloc[:, 1:6:], annot=True, linewidths=.5) 
ax.set_yticklabels([i.strftime("%Y-%m-%d %H:%M:%S") for i in df1.TIMESTAMP], rotation=0) 

HTH

+0

感謝您的回覆。我編輯我的帖子來解釋更多的問題 – Bio

+1

@Bio要麼你做'df1.set_index(「TIMESTAMP」,inplace = 1)''或者你用'ax.set_yticklabels(...)'來做詭計,而不是兩個! – jrjc

+0

它的工作原理!非常感謝你 – Bio