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

Density mapbox tooltips


I’ve had a problem with tooltips in the density heatmap:
The documentation specifies that for showing text in tooltips you can pass a string or an array, but, while when I pass a String it works, when an array is given it doesn’t

Can anybody help me?

Thank you so much!

        density['data'] = [
                lat=lat, # Array
                lon=lon, # Array
                text=texttype, # => This is a string, I need an Array

Captura de pantalla de 2019-11-27 12-20-41


Parent: data[type=densitymapbox]
Type: string or array of strings
Default: ""

Sets text elements associated with each (lon,lat) pair If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace’s (lon,lat) coordinates. If trace hoverinfo contains a “text” flag and “hovertext” is not set, these elements will be seen in the hover labels.

Hi @Sampal, below is a working example passing the array as customdata and then using a hovertemplate (which is the recommended way to tune the tooltip in Please see for more info on the hovertemplate.

import pandas as pd
quakes = pd.read_csv('')

import plotly.graph_objects as go
fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude, radius=10,
                                customdata=quakes.Date, hovertemplate='z: %{z} <br> %{customdata}',
fig.update_layout(mapbox_style="stamen-terrain", mapbox_center_lon=180)
1 Like

Also, would you mind modifying the title of the post so that it says “density mapbox” instead of “density heatmap” ? It would make easier for people for are looking for information in the forum.

1 Like

Thank you very much @Emmanuelle, my problem is solved with this solution.

Title updated :wink:

1 Like