Search code examples
pythonplotly

Plotly.graph_objects map, how to update range_color property?


This is my map and I made the countries from green to red by tax rate, but color range is 0 to 200 now how can i change this property?

import plotly.graph_objects as go

colorscale = ["rgb(0, 255, 0)", "rgb(255, 165, 0)", "rgb(255, 0, 0)"]

fig = go.Figure(data=go.Choropleth(
    locations=df_taxes['Country'],
    locationmode='country names',
    z=df_taxes['Total tax rate'],
    colorscale=colorscale,
    colorbar=dict(title='Vergi Oranı'),
))

fig.add_trace(go.Scattergeo(
    locationmode='country names',
    locations=df_taxes['Country'],
    text=df_taxes['Total tax rate'],
    mode='text',
    textposition='top center',
    showlegend=False
))


fig.update_layout(
    margin={"r": 0, "t": 0, "l": 0, "b": 0},
)

fig.show()

enter image description here

I need just color_range code by graph objects.


Solution

  • import plotly.graph_objects as go
        
    colorscale = ["rgb(0, 255, 0)","rgb(255, 165, 0)", "rgb(255, 0, 0)"]
        
    fig = go.Figure(data=go.Choropleth(
        locations=df_taxes['Country'],
        locationmode='country names',
        z=df_taxes['Total tax rate'],
        colorscale=colorscale,
        colorbar=dict(title='Vergi Oranı'),
        zmin=0, #zmin and zmax.
        zmax=100
    ))
        
    fig.add_trace(go.Scattergeo(
        locationmode='country names',
        locations=df_taxes['Country'],
        text=df_taxes['Total tax rate'],
        mode='text',
        textposition='top center',
        showlegend=False
    ))
    
    fig.update_layout(
        margin={"r": 0, "t": 0, "l": 0, "b": 0},
    )
    
    fig.show()