I'm trying to generate plots as textures for use within a real-time graphics application (written using the pythonOgre graphics engine). I'm brand new to matplotlib so please bear with me. Two questions, one easy, one possibly hard.
In the following code snippet, I create and draw a pie chart, do some intermediate work, update the pie fractions, and redraw. I end up with the second version superimposed on the first. Initially I thought it was simply a matter of clearing the canvas, but as I repeat this test with more and more updates, the redraw seems to slow down - this makes me think that each redraw is actually rerendering all the layers. Is this the case? If so, how do I avoid it?
# create matplotlib figure
figure = Figure(figsize=(4,3), dpi=200, frameon=True)
figureCanvas = FigureCanvas(figure)
# unchanging details of pie chart
ax = figure.add_subplot(111) # pie plot
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
ax.set_title('Example pyOgre Pie Chart')
# update pie chart
# matplotlib draw
And the harder question. I need access to the address of the raw image buffer. (I assume this is a contiguous block of c-allocated memory?) Presently, I copy into a ctypes buffer but this slows things down significantly. Is there an alternative approach?
# retrieve buffer from matplotlib
height = int( figureCanvas.get_renderer().height )
width = int( figureCanvas.get_renderer().width )
# extract image buffer (need as void ptr to contiguous byte array)
buff = figureCanvas.buffer_rgba(0,0)
cbuffer[:] = buff[:] ## would prefer to eliminate this step
address = ctypes.addressof(cbuffer)
Any help is much appreciated ...
Darran Edmundson [darran@...1769...]