Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Update example for advanced charts with Vizro-AI #611

Merged
merged 9 commits into from
Aug 6, 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
nadijagraca marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified vizro-ai/docs/assets/user_guides/map_chart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vizro-ai/docs/assets/user_guides/surface_plot.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vizro-ai/docs/pages/user-guides/chart-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The next chart we'll look at is a geographical map chart to visualize spatial pa
from dotenv import load_dotenv
load_dotenv()

df = px.data.wind()
df = px.data.gapminder()

vizro_ai = VizroAI(model="gpt-4-0613")
fig = vizro_ai.plot(df,
Expand Down
28 changes: 16 additions & 12 deletions vizro-ai/docs/pages/user-guides/create-advanced-charts.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# How to create advanced charts
Now, let's explore more advanced visualizations and use Vizro-AI for enhanced formatting.

We'll create an animated bar chart illustrating the population development of each continent over time. Run the code below and look at the result.
We'll create an animated bar chart illustrating the GDP per capita of each continent over time. Run the code below and look at the result.

!!! example "Vizro-AI animated chart"

Expand All @@ -13,15 +13,16 @@ We'll create an animated bar chart illustrating the population development of ea
df = px.data.gapminder()

vizro_ai = VizroAI()
fig = 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.")
fig = vizro_ai.plot(df, "Visualize GDP per capita over the years for each country using map chart.")
fig.show()
```
=== "Result"
[![AnimatedChart1]][AnimatedChart1]

[AnimatedChart1]: ../../assets/tutorials/chart/animated_bar_chart_1.png
[AnimatedChart1]: ../../assets/tutorials/chart/advanced_chart_1.png

Having unveiled our animated bar chart showcasing population development per country, it's clear 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.
Having unveiled our animated map chart showcasing GDP per capita development per country, it's clear that the map area is small, and it is very difficult to differentiate countries.
Next, we will try to tweak our prompt to improve the overall layout.

!!! example "Vizro-AI animated chart"

Expand All @@ -33,18 +34,20 @@ Having unveiled our animated bar chart showcasing population development per cou
df = px.data.gapminder()

vizro_ai = VizroAI()
fig = 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. Please improve layout.")
fig = vizro_ai.plot(df,
"""Visualize GDP per capita over the years for each country using animated map chart.
Show countries on the map. Increase the width and height of the figure.""")
fig.show()
```
=== "Result"
[![AnimatedChart2]][AnimatedChart2]

[AnimatedChart2]: ../../assets/tutorials/chart/animated_bar_chart_2.png
[AnimatedChart2]: ../../assets/tutorials/chart/advanced_chart_2.png


By incorporating the directive `Please improve layout`, we've successfully refined our animation and are now able to better interpret our result.
By incorporating the directive `Increase the width and height of the figure.` and `Show countries on the map.` we've successfully refined our animation.

Upon closer inspection, two challenges emerge: the legend overlaps the x-axis and the y-axis range is insufficient to capture the full spectrum of Asia's population development. Let's run the code below to improve the chart.
Upon closer inspection, the title is too long and the color palette used does not match out needs. We can fix those issues with better and more specific prompting. Let's run the code below to visually improve the chart.
nadijagraca marked this conversation as resolved.
Show resolved Hide resolved

!!! example "Vizro-AI animated chart"

Expand All @@ -56,16 +59,17 @@ Upon closer inspection, two challenges emerge: the legend overlaps the x-axis an
df = px.data.gapminder()

vizro_ai = VizroAI()
fig = 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.")
fig = vizro_ai.plot(df,
"""Visualize GDP per capita over the years for each country using animated map chart.
Show countries on the map. Increase the width and height of the figure.
Set title to be: `GDP per Capita over the years`. Use `Blues` as color sequence. """)
fig.show()
```
=== "Result"
[![AnimatedChart3]][AnimatedChart3]

[AnimatedChart3]: ../../assets/tutorials/chart/animated_bar_chart_3.png
[AnimatedChart3]: ../../assets/tutorials/chart/animated_advanced_chart.gif

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

Advanced charts are well-suited for [Vizro](https://github.com/mckinsey/vizro/tree/main/vizro-core) dashboard applications. You can create a chart using `vizro-ai` to plug into your `vizro` dashboard in seconds!

![chart-into-dashboard](../../assets/tutorials/chart_into_dashboard.gif)
Loading