Pie chart on the map

Hi everyone,
I would like to know if there is a way to plot pie charts on the map.

Bests,
Ditsuhi

Hi @Ditsuhi it is possible to some extent but the interaction between the map and the pie is not perfect, since the traces live in different axes. See the example below

import plotly.express as px
import plotly.graph_objects as go

df = px.data.gapminder().query("year==2007")
fig = px.choropleth(df, locations="iso_alpha",
                    color="lifeExp", # lifeExp is a column of gapminder
                    hover_name="country", # column to add to hover information
                    color_continuous_scale=px.colors.sequential.Plasma)
fig.add_trace(go.Pie(values=[1, 2, 3], domain_x=(0.1, 0.3), domain_y=(0.2, 0.4)))
fig.show()

You can control the position of the pie thanks to domain_x and domain_y (corresponding to plot fractions) but if you pan or zoom on the map the pie will stay at the same place. I don’t think it’s possible to define a pie at a position which is in geo axis coordinates.

1 Like

Is that still the case? I am trying to build something like this: Matplotlib Basemap tutorial 06: Real Case pie charts – GΓ©ophysique.be