Search code examples
pythonnumpymatplotlibplotreal-time

How to plot a bar plot in realtime using matplotlib


I've a continuous stream of data which is basically bins of a histogram. I can plot a in real-time if use something like following:

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) 

But this only plots a line-plot.

The issue is I can't find something similar to set_ydata for a bar plot.


Solution

  • Does this do the job for you?

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

    where i is the index for a particular bar and x is the desired height.