Ejemplo n.º 1
0
def figure_to_image(figure):
    """
    Draws the previously created "figure" in the supplied Image Element
    :param element: an Image Element
    :param figure: a Matplotlib figure
    :return: The figure canvas
    """

    plt.close('all')  # erases previously drawn plots
    canv = FigureCanvasAgg(figure)
    buf = io.BytesIO()
    canv.print_figure(buf, format='png')
    if buf is None:
        return None
    buf.seek(0)
    return buf.read()
Ejemplo n.º 2
0
def draw_figure(figure):
    """
    Draws the previously created "figure" in the supplied Image Element

    :param figure: a Matplotlib figure
    :return: BytesIO object
    """

    plt.close('all')  # erases previously drawn plots
    canv = FigureCanvasAgg(figure)
    buf = io.BytesIO()
    canv.print_figure(buf, format='png')
    if buf is not None:
        buf.seek(0)
        # element.update(data=buf.read())
        return buf
    else:
        return None