Hey guys I’m trying to create a world map where each country gets assigned a certain percentage. When hovering over the country I’d like to display this percentage.
Is there a way to display as a percentage? So instead of 12.04 I would like to display 12.04%.
I tried using zhoverformat (even though it does not seem to be supported for choropleth) and hovertemplate without success:
trace = dict (
type = ‘choropleth’,
locations = df[‘ISO-3’],
z = df[‘Percentage’],
text = df[‘Country Label’],
hovertemplate=’,.0’,
colorbar=dict(
title="% Exposure",
tickformat=",.0%",
),
)
In the meantime, your best option would be compute the tooltip strings yourself and set them as the text property of the choropleth trace. Then you can set hoverinfo='text' in order to display only the custom text. This example might be helpful https://plot.ly/python/choropleth-maps/#united-states-choropleth-map.
Thank you for your reply! With your suggested workaround I can display the number as a percentage.
Can I use newlines in the text attribute of the trace? I would like to have the percentage and country below each other instead of on the same line. (It looks a bit weird for countries with long names)
I tried to include a newline:
trace = dict(
type = 'choropleth',
locations = ['NLD'],
z = [0.10],
# text = ['0.10%' + os.linesep + 'The Netherlands'],
text = ['0.10%\nThe Netherlands'],
hoverinfo = "text",