Plotly Scatter Points on Maps – Removing Longitude and Latitude from text
Question:
I am following this example very closely to experiment with plotting scatter points on maps and this is working perfectly: https://plot.ly/python/scatter-plots-on-maps/
However, when you hover over each scatter point you will notice the text is shown along with the latitude and longitude. Is there a way to remove the two coordinates from the displayed text?
Answers:
You should be able to set hoverinfo="text"
to achieve this. Here is the relevant documentation page: https://plot.ly/python/hover-text-and-formatting/
Though lat/lon is include by default in scatter_geo and scatter_mapbox, there are two ways to customize values include in the tooltip and both use the hover_data
parameter.
From the docs:
hover_data: list of str or int, or Series or array-like, or dict
Passing a list/array only adds elements to the tooltip. To completely control what is displayed (in your case excluding lat/lon) pass in a dictionary with column names as keys and True/False as values. e.g.
fig = px.scatter_mapbox(data,
lat="lat",
lon="lon",
hover_name="column_to_display_at_top_of_tooltip",
hover_data={"column_you_want_displayed_in_tooltip":True,
"lat":False,
"lon":False,
}
)
I am following this example very closely to experiment with plotting scatter points on maps and this is working perfectly: https://plot.ly/python/scatter-plots-on-maps/
However, when you hover over each scatter point you will notice the text is shown along with the latitude and longitude. Is there a way to remove the two coordinates from the displayed text?
You should be able to set hoverinfo="text"
to achieve this. Here is the relevant documentation page: https://plot.ly/python/hover-text-and-formatting/
Though lat/lon is include by default in scatter_geo and scatter_mapbox, there are two ways to customize values include in the tooltip and both use the hover_data
parameter.
From the docs:
hover_data: list of str or int, or Series or array-like, or dict
Passing a list/array only adds elements to the tooltip. To completely control what is displayed (in your case excluding lat/lon) pass in a dictionary with column names as keys and True/False as values. e.g.
fig = px.scatter_mapbox(data,
lat="lat",
lon="lon",
hover_name="column_to_display_at_top_of_tooltip",
hover_data={"column_you_want_displayed_in_tooltip":True,
"lat":False,
"lon":False,
}
)