# Vizro is an open-source toolkit for creating modular data visualization applications.
# check out https://github.com/mckinsey/vizro for more info about Vizro
# and checkout https://vizro.readthedocs.io/en/stable/ for documentation.
import vizro.plotly.express as px
from vizro import Vizro
import vizro.models as vm
from vizro._themes._colors import get_colors
COLORS = get_colors()
iris = px.data.iris()
gapminder = px.data.gapminder()
tips = px.data.tips()
tips["size"] = tips["size"].astype(str)
gapminder_positive = gapminder.copy()
gapminder_negative = gapminder.copy()
gapminder_negative["lifeExp"] = -gapminder_negative["lifeExp"]
gapminder_mixed = gapminder.copy()
gapminder_mixed["lifeExp"] = gapminder_mixed["lifeExp"] - gapminder_mixed["lifeExp"].mean()
# FOR STEPH TO CUSTOMIZE
# EXAMPLE:
# COLORS_DIVERGING = ['#d73027', '#f7f7f7', '#003096']
COLORS_DIVERGING = COLORS["DIVERGING_RED_CYAN"]
COLORS_DISCRETE = COLORS["DISCRETE_10"]
COLORS_SEQUENTIAL = COLORS["SEQUENTIAL_CYAN"]
COLORS_SEQUENTIALMINUS = COLORS["SEQUENTIAL_RED"]
page = vm.Page(
title="Default discrete and continuous",
components=[
vm.Graph(
figure=px.choropleth(
gapminder, locations="iso_alpha", color="lifeExp", color_continuous_scale=COLORS_SEQUENTIAL
)
),
vm.Graph(
figure=px.box(
gapminder, x="continent", y="lifeExp", color="continent", color_discrete_sequence=COLORS_DISCRETE
)
),
],
)
page_two = vm.Page(
title="Continuous scales",
layout=vm.Grid(grid=[[0, 1, 2]]),
components=[
vm.Graph(
title="Positive sequential",
figure=px.choropleth(
gapminder_positive, locations="iso_alpha", color="lifeExp", color_continuous_scale=COLORS_SEQUENTIAL
),
),
vm.Graph(
title="Negative sequential",
figure=px.choropleth(
gapminder_negative,
locations="iso_alpha",
color="lifeExp",
color_continuous_scale=COLORS_SEQUENTIALMINUS,
),
),
vm.Graph(
title="Diverging",
figure=px.choropleth(
gapminder_mixed, locations="iso_alpha", color="lifeExp", color_continuous_scale=COLORS_DIVERGING
),
),
],
)
page_three = vm.Page(
title="Discrete with diverging",
components=[
vm.Graph(
title="Diverging",
figure=px.choropleth(
gapminder_mixed, locations="iso_alpha", color="lifeExp", color_continuous_scale=COLORS_DIVERGING
),
),
vm.Graph(
figure=px.box(
gapminder, x="continent", y="lifeExp", color="continent", color_discrete_sequence=COLORS_DISCRETE
)
),
],
)
dashboard = vm.Dashboard(pages=[page, page_two, page_three])
Vizro().build(dashboard).run()