Interactive Zoom Tool on Choropleth Map


#1

Greetings! Let me start out by saying I’m new to plotly, so forgive me if I’m missing something obvious…

At any rate, I have this interactive map (https://plot.ly/~jgodwinWX/0/last-democratic-win) showing a U.S. county map and the last time each county voted for the Democratic Party presidential nominee. What I’m trying to do is be able to have the user of the map zoom in (which would be useful to see small counties like San Francisco, CA; Queens, NY; etc.). Is this possible on the choropleth map, or is it available on something else? I know you can change the scope of the map, but that would require me to make multiple maps.

I’ve searched far and wide and gotten no definitive answer, so any help would be appreciated!

(FWIW, I’m using Python 3, not 2.7).


#2

Hi @jgodwinWX,

pan/zoom are disabled by default for the county choropleth. I think this is because these interactions can be somewhat slow for a large choropleth. But you can re-enable them like this

import plotly.figure_factory as ff
fig = ff.create_choropleth(...)
fig.layout.xaxis.fixedrange = False 
fig.layout.yaxis.fixedrange = False 

Hope that helps!
-Jon


#3

I get this error when I try the solution:

fig.layout.xaxis.fixedrange = False
AttributeError: ‘dict’ object has no attribute ‘layout’

Any ideas why? Thanks


#4

Hi @maconte01,

That error message looks like it’s coming from plotly.py version < 3. So you could either update to version 3+, or you could do something like

import plotly.figure_factory as ff
fig = ff.create_choropleth(...)
fig['layout']['xaxis']['fixedrange'] = False 
fig['layout']['yaxis']['fixedrange'] = False 

Hope that helps!
-Jon


#5

That worked! Thanks! I will also update my plotly – thanks for pointing that out.


#6

Sorry just got around to attempting this (crazy week was crazy). The second solution worked like a charm, even though I have plot version 3.x. You’re definitely right about it being slow, but nevertheless, it works! Thanks a ton!