# Converting Byte Object to numpy array

**URL:** https://community.plotly.com/t/converting-byte-object-to-numpy-array/40189
**Category:** 📊 Plotly Python
**Created:** [May 28, 2020, 6:50am UTC](https://community.plotly.com/t/converting-byte-object-to-numpy-array/40189 "2020-05-28T06:50:25Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)
#### Post date: [May 28, 2020, 8:20am UTC](https://community.plotly.com/t/converting-byte-object-to-numpy-array/40189/2 "2020-05-28T08:20:54Z")

</div>

Hi @f.batiri

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

```auto
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)

```

---

_[View the full topic](https://community.plotly.com/t/converting-byte-object-to-numpy-array/40189)._
