如何使用 matplotlib 实时绘制条形图

How to plot a bar plot in realtime using matplotlib

我有一个连续的数据流,基本上是直方图的箱子。 如果使用如下内容,我可以实时绘制 a:

import pylab as plt 
from matplotlib.pyplot import figure, show
import numpy as np

plt.ion() 
X = np.linspace(0,4095,16)  
Y = np.linspace(0,10000,16)
f, axarr = plt.subplots(4, sharex=True)
graph_low,  = axarr[0].plot(X,Y,label='SomeLabel')
graph_low.set_ydata(Z) 

但这只绘制了一个线图。

问题是我找不到类似于 set_ydata 的条形图。

这对你有用吗?

ax = plt.bar(left, height)
ax.patches[i].set_height(x)

其中 i 是特定柱的索引,x 是所需的高度。