Converting Byte Object to numpy array

Hi @f.batiri

This is the function that converts Plotly fig image to an array:

import io 
from PIL import Image

def plotly_fig2array(fig):
    #convert Plotly fig to  an array
    fig_bytes = fig.to_image(format="png")
    buf = io.BytesIO(fig_bytes)
    img = Image.open(buf)
    return np.asarray(img)
2 Likes