Black Lives Matter. Please consider donating to Black Girls Code today.

How I can show only one colobar?

def plot_cancer_map(cancer_type):
trc = []
# create layout
layout = dict(
title = ‘U.S {} Cancer’.format(cancer_type),
autosize = False,
width = 1000,
height = 900,
hovermode = ‘closest’,
legend=dict(orientation=“v”),
geo = dict(x=0.7, y=-0.1,bgcolor=“rgba(255, 255, 255, 0)”,font = dict( size=11 ))
)

# select relevant data
years = cancer_group_data.Year.unique()

for i in range(len(years)):
    geo_key = 'geo'+str(i+1) if i != 0 else 'geo'
    temp_df = cancer_group_data[(cancer_group_data['Year'] == 1999+i) & 
                           (cancer_group_data['Leading Cancer Sites'] == cancer_type)]
    # create data
    trc.append(
        dict(type = 'choropleth',
               z= temp_df.Count,
               locations = temp_df.StatesAbb,
               locationmode = 'USA-states',
               colorscale = 'Jet',
               geo = geo_key,
               #name = years[i],
               hoverinfo = 'text+z',
               text = temp_df['States'],
               colorbar=dict(title='Rate Per 100,000')
            )
    )
    layout[geo_key] = dict(
        scope = 'usa',
        showland = True,
        landcolor = 'rgb(229, 229, 229)',
        showcountries = False,
        domain = dict( x = [], y = [] ),
        subunitcolor = "rgb(255, 255, 255)",
    )
    
z = 0
COLS = 4
ROWS = 4
for y in reversed(range(ROWS)):
    for x in range(COLS):
        geo_key = 'geo'+str(z+1) if z != 0 else 'geo'
        layout[geo_key]['domain']['x'] = [float(x)/float(COLS), float(x+1)/float(COLS)]
        layout[geo_key]['domain']['y'] = [float(y)/float(ROWS), float(y+1)/float(ROWS)]
        z = z + 1
    
# create figure
fig = { 'data':trc, 'layout':layout }
# plot in jupyter notebook
iplot(fig)

Hi @yonipick,

To display only one colorbar you can set showscale=False for all but the first trace (https://plot.ly/python/reference/#choropleth-showscale). If you do this, I’d recommend you manually set the zmin/zmax choropleth properties (https://plot.ly/python/reference/#choropleth-zmin) for every trace so that the colors can be compared across traces.

Hope that helps!
-Jon