County choropleths not displaying hoverinfo in offline mode


#1

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!


#2

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


#3

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


#4

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.