首页 > 解决方案 > 实时图表绘制

问题描述

我已将动态更改的对象计数列表传递给根据对象计数绘制图表的函数。但它会抛出一些错误,如 "TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'" ,代码如下,这里 pcount 是实时变化的列表参数。我想要的是一个图表绘图函数,它接受一个在另一个函数中动态变化的列表参数。

def chart(pcount):

    fig = plt.figure(figsize=(2,3))

    axes = fig.add_subplot(1,1,1)

    axes.set_ylim(0, 150)

    plt.style.use("seaborn")

    list1= pcount

    list2=[]

    palette = list(reversed(sns.color_palette("seismic", 2).as_hex()))

    y1, y2, = [], []

    def animate(i):

        y1= list1

        y2= list2.append(random.randint(0, 5))

     
        plt.bar(["Door one", "Door two"], [y1,y2], color=palette)
        


    plt.title("Object count analysis , Year: {} ".format(2021), color=("blue"))

    ani = FuncAnimation(fig, animate, interval=10)

    plt.show()

标签: pythonopencvanimationplotcharts

解决方案


推荐阅读