I have a matplotlib hexbinbuilt in GTK.Windowwhich displays some data (x, y). I want to be plotupdated when new data is received (via UDP). However, I have a problem.
I can make it work in different ways, but none of them were "effective" (meaning - redrawing plottakes too much time). I looked here and tried to simulate my hexbin after the suggested answer, but could not get this to work at all. I keep getting the following error:
TypeError: 'PolyCollection' object is not iterable.
I assume that hexbinsit cannot be updated in the same way as the standard one plots.
Code example:
class graph:
def __init__(self):
self.window = gtk.Window()
self.figure = plt.figure()
self.ax = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self.figure)
self.window.add(self.canvas)
self.graph = None
def plot(self, xData, yData):
if len(xData) > 1 and len(yData) > 1:
self.graph, = self.ax.hexbin(self.xData, self.yData)
def update(self, xData, yData):
self.graph.set_xdata(np.append(self.graph.get_xdata(), xData))
self.graph.set_ydata(np.append(self.graph.get_ydata(), yData))
self.figure.canvas.draw()
The code is used as follows:
graph = graph()
graph.plot(someXData, someYData)
graph.update(newXData, newYData)
, . matplotlib, , . ( , )
, : matplotlib hexbin?
: ',' self.graph = self.ax.hexbin(...)
: AttributeError: 'PolyCollection' object has no attribute 'set_xdata'