首页 > 解决方案 > 如何删除 Seaborn(实时)热图中的注释?

问题描述

我正在尝试制作实时股票热图,它每 0.2 秒更新一次数据,上面有股票代码/价格注释。但是当我第一次开始编写代码时,我发现 Seaborn 在每次调用时都会添加另一个注解,而不会删除前一个注解。有人可以告诉我如何删除以前的注释或编辑已经存在的注释吗?

def animate(i):
    #getting price datas from sql
    mkdatac.execute(stc, (chs,))
    pricerows = mkdatac.fetchall()
    for row in pricerows:
        prices = (np.asarray(pricerows).reshape(1, 2))
        print(prices)
    mkdatac.execute(stt, (chs,))
    stcoderows = mkdatac.fetchall()
    for row in stcoderows:
        symbols = (np.asarray(stcoderows).reshape(1, 2))
        print(symbols)
    
    #making labels(annotation)
    labels = (np.asarray(["{0} \n {1:.2f}".format(symb,value)
                          for symb, value in zip(symbols.flatten(),
                                                 prices.flatten())])
              ).reshape(1,2)

    #drawing heatmap
    sns.heatmap(prices, annot=labels, fmt="", cmap='RdYlGn', linewidths=0.30, ax=ax, cbar=False)

标签: pythonmatplotlibseabornmatplotlib-animation

解决方案


推荐阅读