python - 实时图表绘制
问题描述
我已将动态更改的对象计数列表传递给根据对象计数绘制图表的函数。但它会抛出一些错误,如 "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()
解决方案
推荐阅读
- php - 在 Woocommerce 中使用 ajax 删除购物车项目后刷新购物车
- azure - MyApps Microsoft 的自定义
- java - 树值初始化为 0
- quickfixj - 如何使用 QuickFIX/J 加载资源中的数据字典
- java - 使用 Spring Data JPA 处理 POST 请求中的关系
- node.js - 如何在 Node.js 中停止异步线程
- php - 来自多维数组的 flatten_array 函数 - 未定义
- postgresql - ElasticSearch - 如何在哈希中查询两个时期之间的数据
- php - PHP/IIS - Sessions_save_path - 会话数据已创建但发生错误且无法完成安装
- java - 以文本格式存储由 KeyStoreGenerator 生成的私钥(例如保管库存储) - Java