Skip to content

Explore Vizro-AI

This tutorial serves as an exploration of the extended applications offered by Vizro-AI beyond the initial quickstart guide.

By the end of this tutorial, you will have gained an understanding of different language options and leveraging Vizro-AI to enhance the formatting your visualizations.

Let's get started!

1. Install Vizro-AI and get ready to run your code

Before proceeding, ensure the installation of the vizro_ai package by following the steps outlined in the installation guide. Once installed, you can execute your code either by pasting it into a Jupyter notebook cell or running it from a Python script.

Beginners/Code novices

For those new to Python or virtual environments, a user-friendly alternative is available in the installation guide, offering a graphical user interface without the need for terminal commands.

A prerequisite for this tutorial is access to one of the supported large language models. Please refer to the api setup for instructions on setting up the API.

Upon successful setup, your API key should be ready in the environment when you import vizro_ai.

If you would like to customize the .env file location and name, you can set it manually. You can override the default import of the .env file by specifying the path and name of your custom .env file. Please refer to API setup for instructions on customizing the .env file location and name.

2. Create your visualization using different languages

Vizro-AI is versatile, supporting prompts and chart visualizations in multiple languages. Let's explore this capability with two examples, starting with Chinese where we inquire about visualizing the GDP per capita over time.

Vizro-AI Chinese

from vizro_ai import VizroAI
import vizro.plotly.express as px

df = px.data.gapminder()

vizro_ai = VizroAI()
vizro_ai.plot(df, "请画一个世界年均GDP的趋势图")

ChineseChart

Subsequently, we'll switch to German and prompt the visualization of life expectancy in the United States over time, comparing it to the global life expectancy trend. For this example, we'll include explain=True to obtain comprehensive insights into both the data and the generated code.

Vizro-AI German

from vizro_ai import VizroAI
import vizro.plotly.express as px

df = px.data.gapminder()

vizro_ai = VizroAI()
vizro_ai.plot(df, "Visualiere den Trend von der Lebenserwartung in USA über die Jahre im Vergleich zur Veränderung der weltweiten Lebenserwartung über die Jahre und kreiere eine deutsche Visualisierung", explain=True)

GermanChart

3. Create advanced charts and formatting

Now, let's explore more advanced visualizations and leverage Vizro-AI for enhanced formatting.

To begin, we'll create an animated bar chart illustrating the population development of each continent over time. Let's run the code below and look at the result.

Vizro-AI animated chart

from vizro_ai import VizroAI
import vizro.plotly.express as px

df = px.data.gapminder()

vizro_ai = VizroAI()
vizro_ai.plot(df, "The chart should be an animated stacked bar chart with popoluation on the y axis and continent on the x axis with all respective countries, allowing you to observe changes in the population over consecutive years.")

AnimatedChart1

Having unveiled our animated bar chart showcasing population development per country, it's apparent that crucial details are overshadowed by the legend. Next, we will try to tweak our prompt to group the countries into continents and improve the overall layout.

Vizro-AI animated chart

from vizro_ai import VizroAI
import vizro.plotly.express as px

df = px.data.gapminder()

vizro_ai = VizroAI()
vizro_ai.plot(df, "The chart should be an animated stacked bar chart with popoluation on the y axis and continent on the x axis with all respective countries, allowing you to observe changes in the population over consecutive years. Please improve layout.")

AnimatedChart2

Great, by incorporating the directive Please improve layout, we've successfully refined our animation and are now able to better interpret our result.

Now, upon closer inspection, two challenges emerge. Firstly, the legend overlaps the x-axis. Secondly, the y-axis range is insufficient to capture the full spectrum of Asia's population development. Let's run the code below and see how we can improve and finalize our chart.

Vizro-AI animated chart

from vizro_ai import VizroAI
import vizro.plotly.express as px

df = px.data.gapminder()

vizro_ai = VizroAI()
vizro_ai.plot(df, "The chart should be an animated stacked bar chart with population on the y axis and continent on the x axis with all respective countries, allowing you to observe changes in the population over consecutive years. Make sure that y axis range fits entire data. Please improve layout and optimize layout of legend.")

AnimatedChart3

Congratulations! You've now gained insights into harnessing the power of Vizro-AI for crafting advanced charts and elevating formatting. Don't forget, enabling explain=True is a good way of learning more about how a chart can be further improved and formatted.

Those advanced charts are well-suited for ('vizro')[https://github.com/mckinsey/vizro/tree/main/vizro-core] dashboard applications. Try to create a chart by vizro-ai and plug it in your vizro dashboard in seconds! chart-into-dashboard