def image_to_base64(image):
    ax = image.axes
    binary_buffer = io.BytesIO()

    # image is saved in axes coordinates: we need to temporarily
    # set the correct limits to get the correct image
    lim = ax.axis()
    ax.axis(image.get_extent())
    image.write_png(binary_buffer)
    ax.axis(lim)

    binary_buffer.seek(0)
    return base64.b64encode(binary_buffer.read()).decode('utf-8')
Convert a matplotlib image to a base64 png representation
dataset/ETHPy150Open plotly/plotly.py/plotly/matplotlylib/mplexporter/utils.py/image_to_base64