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

County choropleths not displaying hoverinfo in offline mode

I’m trying to make an offline county choropleth map, but nothing is shown when I hover over the map unless I plot it in online mode.

This example from USA County Choropleth Maps tutorials doesn’t display any hoverinfo for me:

import plotly as py
import plotly.figure_factory as ff

import numpy as np
import pandas as pd

df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv')
df_sample_r = df_sample[df_sample['STNAME'] == 'California']

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

colorscale = [
    'rgb(193, 193, 193)',
    'rgb(239,239,239)',
    'rgb(195, 196, 222)',
    'rgb(144,148,194)',
    'rgb(101,104,168)',
    'rgb(65, 53, 132)'
]

fig = ff.create_choropleth(
    fips=fips, values=values, scope=['CA', 'AZ', 'Nevada', 'Oregon', ' Idaho'],
    binning_endpoints=[14348, 63983, 134827, 426762, 2081313], colorscale=colorscale,
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, round_legend_values=True,
    legend_title='Population by County', title='California and Nearby States'
)
py.offline.plot(fig, filename='choropleth_california_and_surr_states_outlines')

However, hoverinfo does work with a simpler example from the tutorial if I use py.offline.plot(fig, validate=False), but validate=False doesn’t help my other plots.


import plotly as py
import plotly.figure_factory as ff

fips = ['06021', '06023', '06027',
        '06029', '06033', '06059',
        '06047', '06049', '06051',
        '06055', '06061']
values = range(len(fips))

fig = ff.create_choropleth(fips=fips, values=values)
py.offline.plot(fig, validate=False)

Does anyone know what I’m doing wrong or if this isn’t something supported with the python library in offline mode?

Thank you!

Hi @iRowebot,

I see what you mean, and that is really odd! I’ll open a bug report, but it looks like hoverinfo worked as expected in a slightly older version of plotly.js. In the meantime, you can override the version of plotly.js used like this:

py.offline.plot(fig,
                filename='choropleth_california_and_surr_states_outlines',
                include_plotlyjs='https://cdn.plot.ly/plotly-1.42.3.min.js')

Hope that helps for the time being!
-Jon

1 Like

Issue: https://github.com/plotly/plotly.py/issues/1429

Thank you so much!

Trying to get this to work was driving me crazy. I kept re-installing geopandas thinking that might have been the issue.

Hi Jon
I was having the problem with the hover not showing on the county choropleth. I implemented the fix you suggested. I had been rendering the plots in line in my jupyter notebook with just:

fig.layout.template = None
fig.show()

So I used the offline plotting code, and now my browser opens a new tab with the plot with the hover text showing. But the plot inline in Jupyter does not have the hover showing. I don’t want the plot in a new tab. Do you know how I can get the hover showing for the inline Jupyter plot?

Thanks,
Ross

There is another weird thing about county choropleth.
#this one does NOT have hover info.
import plotly.figure_factory as ff
fips = [‘06015’]
values=[1234]
fig = ff.create_choropleth(fips=fips, values=values,scope=[‘California’],)
fig.layout.template = None
fig.show()

However,
#this one has hover info.
import plotly.figure_factory as ff
fips = [‘06013’]
values=[1234]
fig = ff.create_choropleth(fips=fips, values=values,scope=[‘California’],)
fig.layout.template = None
fig.show()

Why? Thank you!

Why would my hover text not show even in the online mode? It’s so weird.
I did a test with some fips. Some counties are shown with hover texts, but some are not. When I included the fips that do not have the hover text shown in the list of fips, all the counties do not have their hover texts shown. Any help? Thank you