lida icon indicating copy to clipboard operation
lida copied to clipboard

Haven't been able to generate a visualization with Altair

Open rmitra34 opened this issue 2 years ago • 1 comments

Hello, I've been playing around with the toolkit for a couple days and it's working very well with the seaborn Library. However I would like to generate VegaLite specifications so I switched to the altair library. However, I've been having issues with generating visualizations through this library. I am running the following code snippet to produce a visualization.

new_goal = Goal(index=1, question='Show the relationship between budget and rating', visualization='scatterplot', rationale='Both are quantitative attributes so a scatterplot is necessary to find the correlation')
goals.append(new_goal)
temp = Summary(name=summary['name'], file_name=summary['file_name'], dataset_description=summary['dataset_description'], field_names=summary['field_names'], fields=summary['fields'])
library="altair"
textgen_config = TextGenerationConfig(n=1, temperature=0.2, use_cache=True)
charts = lida.visualize(summary=temp, goal=new_goal, textgen_config=textgen_config, library=library) 
plot_raster(charts[0].raster)

The code block produces the following error: Screenshot 2023-08-28 at 11 41 38 AM Is there something wrong with how I'm switching the library to altair?

rmitra34 avatar Aug 28 '23 15:08 rmitra34

Hi @rmitra34 ,

Thanks for trying this out. At the moment, visualize method returns a spec field when altair is the selected library. spec is a dictionary representation of the visualization. Currently, lida does does not return a visualization raster for altair (rendering altair visualizations in a headless manner is currently hairy).

You can then load this as follows

import altair as alt
spec = charts[0].spec 
new_chart = alt.Chart.from_dict(spec)
new_chart.data = lida.data
new_chart

I am thinking of ways to make this workflow better and will update here once I have something

victordibia avatar Aug 29 '23 15:08 victordibia