我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)
我有一個熱圖像附
我現在的問題是如何能夠通過我的時間戳及其相應值替換熱圖地圖(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,看最後的圖像,還有一個問題:圖像太小且有右側兩個垂直線(規模)。我希望我'立即清除
感謝您的回覆。我編輯我的帖子來解釋更多的問題 – Bio
@Bio要麼你做'df1.set_index(「TIMESTAMP」,inplace = 1)''或者你用'ax.set_yticklabels(...)'來做詭計,而不是兩個! – jrjc
它的工作原理!非常感謝你 – Bio