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

How can I change the hover labels into static labels?

When I draw a world Choropleth map, I have to export the picture in PNG, so the hover interaction is unnecessary, I need the countries’ name to be shown in the picture statically. So, need your help!
thanks a lot.

Hey @wangyp1937,

you can add an additional scattergeo trace like such:

trace2 = go.Scattergeo(
       locations = df['code'],
       locationmode = 'USA-states',
       text = df['code'],
       mode = 'text') 

data = [trace1,trace2]

Thank you very much! But I met a new problem, I don’t know how to place your code into my original code, so I sincerely appreciate your help again!
This is my original code:

#!usr/bin/python

encoding=utf8

import sys
reload(sys)
sys.setdefaultencoding( “utf-8” )

import plotly.plotly as py
import pandas as pd

df = pd.read_csv(‘G20 data.csv’)

data = [ dict(
type = ‘choropleth’,
locations = df[‘code’],
z = df[‘article_number’],
text = df[‘name’],
#colorscale = [[0,“rgb(5, 10, 172)”],[0.35,“rgb(40, 60, 190)”],[0.5,“rgb(70, 100, 245)”],[0.6,“rgb(90, 120, 245)”],[0.7,“rgb(106, 137, 247)”],[1,“rgb(220, 220, 220)”]],
colorscale=[[0,’#0018ad’],[0.2,’#0222e3’],[0.4,’#3f5afd’],[0.6,’#7083fb’],[0.8,’#90a0fd’],[1,’#a3b0ff’]],
autocolorscale = False,
reversescale = True,
marker = dict(
line = dict (
color = ‘rgb(180,180,180)’,
width = 0.5
) ),
colorbar = dict(
autotick = False,
tickprefix = ‘’,
title = ‘number of articles’),
) ]

layout = dict(
title = "G20 countries’ scientific articles"
geo = dict(
showframe = False,
showcoastlines = False,
showlocations=True,
showland=True,
landcolor=’#f0f0f0’,
projection = dict(type = ‘Mercator’)
)
)

fig = dict( data=data, layout=layout )
py.plot( fig, validate=False, filename=‘d3-world-map-2’)

#!usr/bin/python
# encoding=utf8

import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )


import plotly.plotly as py
import pandas as pd

df = pd.read_csv('G20 data.csv')

data = [ dict(
        type = 'choropleth',
        locations = df['code'],
        z = df['article_number'],
        text = df['name'],
        #colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],[0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
        colorscale=[[0,'#0018ad'],[0.2,'#0222e3'],[0.4,'#3f5afd'],[0.6,'#7083fb'],[0.8,'#90a0fd'],[1,'#a3b0ff']],
        autocolorscale = False,
        reversescale = True,
        marker = dict(
            line = dict (
                color = 'rgb(180,180,180)',
                width = 0.5
            ) ),
        colorbar = dict(
            autotick = False,
            tickprefix = '',
            title = 'number of articles'),
      ) ]

layout = dict(
    title = "G20 countries' scientific articles"
    geo = dict(
        showframe = False,
        showcoastlines = False,
        showlocations=True,
        showland=True,
        landcolor='#f0f0f0',
        projection = dict(type = 'Mercator')
    )
)

fig = dict( data=data, layout=layout )
py.plot( fig, validate=False, filename='d3-world-map-2')

add it as a second trace. Thus, something like:

data = [  dict(
              # the trace you already have
          ),
          dict(
              type = 'scattergeo',
              locations = df['code'],
              locationmode = 'USA-states',
              text = df['code'],
              mode = 'text') 
]