Home > OS >  How to colorize lands which have missing values and get their name in plotly choropleth? Add extra v
How to colorize lands which have missing values and get their name in plotly choropleth? Add extra v

Time:01-21

I made a world map with specific data using choropleth from plotly. For some countries I have missing values ​​and this gives me uncolored areas and especially without being able to identify them.

Edit: I found how to colorize the countries with missing values ​​by adding this in the "geo=dict()" of "update_layout":

landcolor = 'lightgray',
showland = True,
showcountries = True,
countrycolor = 'gray',
countrywidth = 0.5,

Which gives this code:

import plotly.graph_objects as go

fig = go.Figure(data = go.Choropleth(
    locations = world_map_df_sous_nutrition["Code zone (ISO3)"],
    z = round((world_map_df_sous_nutrition["Proportion pop en sous-nutrition"]),2),
    text = world_map_df_sous_nutrition["Zone"],
    colorscale = "earth",
    autocolorscale = False,
    reversescale = True,
    marker_line_color = "white",
    marker_line_width = .2,
    colorbar_tickprefix = "%",
    colorbar_title = "Proportion de personnes en sous nutrition"
    ))

fig.update_layout(
    title_text="L'état de la sous-nutrition dans le monde en 2017",
    geo=dict(
        landcolor = 'lightgray',
        showland = True,
        showcountries = True,
        countrycolor = 'gray',
        countrywidth = 0.5,
        showframe=False,
        showcoastlines=False,
        projection_type='equirectangular'
    ),
    annotations = [dict(
        x=0.55,
        y=0.1,
        xref='paper',
        yref='paper',
        text='Source: <a href="https://www.fao.org/faostat/fr/#data">\
            FAO</a>',
        showarrow = False
    )],
    margin={"r":0,"t":0,"l":0,"b":0},  
)



fig.show()

And this image result:

enter image description here

  •  Tags:  
  • Related