microsoft / lida

Automatic Generation of Visualizations and Infographics using Large Language Models
https://microsoft.github.io/lida/
MIT License
2.6k stars 266 forks source link

Converting Graph to matplotlib graph or Saving graph as a image #52

Closed centa-furqan closed 9 months ago

centa-furqan commented 9 months ago

Hi,

I want to convert the graph into the matplotlib graph format or save the graph into the image, How can I achieve this because the current visualization function is not returning enough information to do so. Getting error while accessing the graph via rasterio. i.e. TypeError: Image data of dtype <U44560 cannot be converted to float

Another error that I got while plotting charts[0] is :- AttributeError: 'ChartExecutorResponse' object has no attribute 'savefig' image

centa-furqan commented 9 months ago

@victordibia can you have a look into this :)

victordibia commented 9 months ago

Hi @centa-furqan ,

The ChartExecutor response is a text based representation to make serialization straightforward (send results over a web api). The raster field is a base64 encoded string.

You can convert it to an image and save as follows:

import base64
with open("chartn.png", "wb") as fh:
    fh.write(base64.decodebytes(charts[0].raster.encode()))

Overall, thanks for pointing this out. I'll add a savefig method to the ChartExecutor object.