def _build_image(data, cmap='gray'):
 import matplotlib.pyplot as plt
 from matplotlib.figure import Figure
 from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
 figsize = data.shape[::(-1)]
 if (figsize[0] == 1):
  figsize = tuple(figsize[1:])
  data = data[:, :, 0]
 fig = Figure(figsize=figsize, dpi=1.0, frameon=False)
 FigureCanvas(fig)
 cmap = getattr(plt.cm, cmap, plt.cm.gray)
 fig.figimage(data, cmap=cmap)
 output = BytesIO()
 fig.savefig(output, dpi=1.0, format='png')
 return base64.b64encode(output.getvalue()).decode('ascii')

def _build_image ( data , cmap = 'gray' ) : import matplotlib . pyplot as plt from matplotlib . figure import Figure from matplotlib . backends . backend_agg import FigureCanvasAgg as FigureCanvas figsize = data . shape [ : : ( - 1 ) ] if ( figsize [ 0 ] == 1 ) : figsize = tuple ( figsize [ 1 : ] ) data = data [ : , : , 0 ] fig = Figure ( figsize = figsize , dpi = 1.0 , frameon = False ) FigureCanvas ( fig ) cmap = getattr ( plt . cm , cmap , plt . cm . gray ) fig . figimage ( data , cmap = cmap ) output = BytesIO ( ) fig . savefig ( output , dpi = 1.0 , format = 'png' ) return base64 . b64encode ( output . getvalue ( ) ) . decode ( 'ascii' )
build an image encoded in base64 .