在Python中创建实时热图

时间:2019-01-27 15:52:53

标签: python pandas seaborn heatmap

我正在尝试做的事情:

我正在尝试通过将Excel表中的数据读取到Pandas DataFrame中并使用Seaborn创建热图来创建实时热图。我执行代码时看到以下错误。我想念什么吗?我也尝试了其他几种组合,但是输出与预期不符。

代码:

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

# The Animate function
def animate(i):
    """Preprocessing the columns to add Date and Time columsn by removing the HOURS columns"""
    arch_gen_file = pd.read_excel('arch_gen_1.xls',parse_dates=['HOUR'])
    arch_gen_file['Date'] = [d.date() for d in arch_gen_file['HOUR']]
    arch_gen_file['Time'] = [d.time() for d in arch_gen_file['HOUR']]
    arch_gen_file.drop(['HOUR'], axis=1,inplace=True)
    arch_gen_file_matrix = arch_gen_file.pivot("Date", "Time", "ARCHIVES")
    arch_gen_file_matrix = arch_gen_file_matrix.fillna(0.0)
    ax.clear()
    ax.plot(sns.heatmap(arch_gen_file_matrix,cmap='rocket'))    
anime = animation.FuncAnimation(fig,animate,interval=100)
plt.show()

错误

TypeError: float() argument must be a string or a number, not 'AxesSubplot'

1 个答案:

答案 0 :(得分:0)

ax.plot(sns.heatmap(arch_gen_file_matrix,cmap='rocket'))行毫无意义。 plot将需要为其提供实际数据。相反,您想呼叫sns.heatmap,所以将其替换为

sns.heatmap(arch_gen_file_matrix, cmap='rocket', ax=ax)