Atheer
Atheer

Reputation: 85

Change parameters for plotly maps

I'm trying to plot the intensity of CO2 emissions per country using plotly ,

Most of the countries don't even exceed 10k, but the color range is from 0 to 35k , how do I change that? map Here's my code:

def enable_plotly_in_cell():
  import IPython
  from plotly.offline import init_notebook_mode
  display(IPython.core.display.HTML('''<script src="/static/components/requirejs/require.js"></script>'''))
  init_notebook_mode(connected=False)

data = dict(type = 'choropleth', 
           locations = fmmcgrf['Entity'],
           locationmode = 'country names',
           z = fmmcgrf['CO2'], 
           text = fmmcgrf['Entity'],
           colorbar = {'title':'CO2'})
layout = dict(title = 'Co2', 
             geo = dict(showframe = False, 
                       projection = {'type': 'winkel tripel'}))
map = go.Figure(data = [data], layout=layout)
enable_plotly_in_cell()
map.show()

Upvotes: 0

Views: 87

Answers (1)

r-beginners
r-beginners

Reputation: 35230

I customized the color bar with the example from the official reference.

import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')

fig = go.Figure(data=go.Choropleth(
    locations = df['CODE'],
    z = df['GDP (BILLIONS)'],
    text = df['COUNTRY'],
    colorscale = 'Blues',
    autocolorscale=False,
    reversescale=True,
    marker_line_color='darkgray',
    marker_line_width=0.5,
    colorbar_tickprefix = '$',
    colorbar_tickvals=[0,10000,15000],# update
    colorbar_title = 'GDP<br>Billions US$',
))

fig.update_layout(
    title_text='2014 Global GDP',
    geo=dict(
        showframe=False,
        showcoastlines=False,
        projection_type='equirectangular'
    ),
)

fig.show()

enter image description here

Upvotes: 1

Related Questions