o
    ed                     @   s   dddZ dS )Tc                    sd   ddl zddlm ddlm  m W n ty"   td Y nw  fdd}|| }|S )a  Render matplotlib figure to numpy format.

    Note that this requires the ``matplotlib`` package.

    Args:
        figure (matplotlib.pyplot.figure) : figure
        close (bool): Flag to automatically close the figure

    Returns:
        numpy.array: image in [HWC] order
        Nzplease install matplotlibc                    sl    | }|  j| jd}| j \}}|||dgd d d d ddf } r4|  |S )N)Zdtype   r      )	ZFigureCanvasAggZdrawZ
frombufferZbuffer_rgbaZuint8canvasZget_width_heightZreshapeclose)Zfigurer   datawhZ	image_hwcr   npZpltZplt_backend_agg JD:\Projects\ConvertPro\env\Lib\site-packages\visualdl/utils/figure_util.pyrender_to_rgb$   s   
&
z&figure_to_image.<locals>.render_to_rgb)numpyZmatplotlib.pyplotZpyplotZmatplotlib.backends.backend_aggbackendsZbackend_aggModuleNotFoundErrorprint)Zfiguresr   r   imager   r	   r   figure_to_image   s   
r   N)T)r   r   r   r   r   <module>   s   