Search code examples
pythonplotlydata-scienceplotly-python

How to remove Antarctica from plotly world map?


I'm using plotly python library in order to make a choropleth. The data of choropleth (choc_df) has been handled by pandas. The choropleth is drawn by this code:

import plotly.graph_objects as go

go.Figure(data=go.Choropleth(
    locations=choc_df['ISO'],
    text=choc_df['company_location'],
    marker_line_color='black',
    marker_line_width=0.5,
    autocolorscale=False,
    colorscale='brbg_r',
    z=choc_df['rating'],
    customdata=choc_df['number'],
    hovertemplate="<br>".join([
        "<b>%{text}</b>",
        "Number of brands: %{customdata}",
        "Rating: %{z}",
    ]) + '<extra></extra>',
), layout=dict(title='Rating',
        geo=dict(showcountries=True, countrycolor='#444444', showlakes=False)
))

I'm happy with the result: resulting_choropleth The only thing that bothers me is the amount of space that Antartica takes for no reason :D. Is there a way to remove it from map?


Solution

  • I got it! Color Antarctica and it's border white (or whatever color your background is).

    #using Plotly sample data
    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)
    

    Original

    Original

    "Hidden" Antarctica

    fig.add_trace(go.Choropleth(locations=['ATA'],
                z=[0],
                colorscale=[[0,'white'], [1,'white']],
                marker_line_color='white',
                showlegend=False,
                showscale=False)
          )
    

    "Hidden" Antarctica

    Optional Zoom

    fig.update_geos(lataxis_range=[-59, 90])
    

    Optional Zoom