def figure_buffer(figs):
    '''Extract raw image buffer from matplotlib figure shaped as 1xHxWx3.'''
    assert len(figs) > 0, 'No figure buffers given. Forgot to return from draw call?'
    buffers = []
    w, h = figs[0].canvas.get_width_height()
    for f in figs:
        wf, hf = f.canvas.get_width_height()
        assert wf == w and hf == h, 'All canvas objects need to have same size'
        buffers.append(np.fromstring(f.canvas.tostring_rgb(), dtype=np.uint8).reshape(h, w, 3))

    return np.stack(buffers)
def figure_buffer ( figs ) : assert len ( figs ) > 0 , 'No figure buffers given. Forgot to return from draw call?' buffers = [ ] w , h = figs [ 0 ] . canvas . get_width_height ( ) for f in figs : wf , hf = f . canvas . get_width_height ( ) assert wf == w and hf == h , 'All canvas objects need to have same size' buffers . append ( np . fromstring ( f . canvas . tostring_rgb ( ) , dtype = np . uint8 ) . reshape ( h , w , 3 ) ) return np . stack ( buffers )
Extract raw image buffer from matplotlib figure shaped as 1xHxWx3.