Skip to main content
 首页 » 编程设计

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

2024年10月25日11cloudgamer

我有一个连续的数据流,基本上是直方图的 bin。 如果使用如下内容,我可以实时绘制 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 是所需的高度。