@@ -300,6 +300,8 @@ def _intervals_as_labels(array_of_intervals, round_legend_values, exponent_forma
300300def _calculations (df , fips , values , index , f , simplify_county , level ,
301301 x_centroids , y_centroids , centroid_text , x_traces ,
302302 y_traces , fips_polygon_map ):
303+ # 0-pad FIPS code to ensure exactly 5 digits
304+ padded_f = str (f ).zfill (5 )
303305 if fips_polygon_map [f ].type == 'Polygon' :
304306 x = fips_polygon_map [f ].simplify (
305307 simplify_county
@@ -311,10 +313,11 @@ def _calculations(df, fips, values, index, f, simplify_county, level,
311313 x_c , y_c = fips_polygon_map [f ].centroid .xy
312314 county_name_str = str (df [df ['FIPS' ] == f ]['COUNTY_NAME' ].iloc [0 ])
313315 state_name_str = str (df [df ['FIPS' ] == f ]['STATE_NAME' ].iloc [0 ])
316+
314317 t_c = (
315318 'County: ' + county_name_str + '<br>' +
316319 'State: ' + state_name_str + '<br>' +
317- 'FIPS: ' + str ( f ) + '<br>Value: ' + str (values [index ])
320+ 'FIPS: ' + padded_f + '<br>Value: ' + str (values [index ])
318321 )
319322
320323 x_centroids .append (x_c [0 ])
@@ -337,7 +340,7 @@ def _calculations(df, fips, values, index, f, simplify_county, level,
337340 text = (
338341 'County: ' + county_name_str + '<br>' +
339342 'State: ' + state_name_str + '<br>' +
340- 'FIPS: ' + str ( f ) + '<br>Value: ' + str (values [index ])
343+ 'FIPS: ' + padded_f + '<br>Value: ' + str (values [index ])
341344 )
342345 t_c = [text for poly in fips_polygon_map [f ]]
343346 x_centroids = x_c + x_centroids
@@ -352,12 +355,11 @@ def _calculations(df, fips, values, index, f, simplify_county, level,
352355
353356def create_choropleth (fips , values , scope = ['usa' ], binning_endpoints = None ,
354357 colorscale = None , order = None , simplify_county = 0.02 ,
355- simplify_state = 0.02 , asp = None , offline_mode = False ,
356- show_hover = True , show_state_data = True ,
357- state_outline = None , county_outline = None ,
358- centroid_marker = None , round_legend_values = False ,
359- exponent_format = False , legend_title = '' ,
360- ** layout_options ):
358+ simplify_state = 0.02 , asp = None , show_hover = True ,
359+ show_state_data = True , state_outline = None ,
360+ county_outline = None , centroid_marker = None ,
361+ round_legend_values = False , exponent_format = False ,
362+ legend_title = '' , ** layout_options ):
361363 """
362364 Returns figure for county choropleth. Uses data from package_data.
363365
@@ -399,12 +401,6 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
399401 Default = 0.02
400402 :param (float) asp: the width-to-height aspect ratio for the camera.
401403 Default = 2.5
402- :param (bool) offline_mode: if set to True, the centroids of each county
403- are invisible until selected over with a dragbox. Warning: this can
404- only be used if you are plotting in offline mode with validate set to
405- False as the params that are being added to the fig dictionary are not
406- yet part of the plotly.py python library. Stay tuned for updates.
407- Default = False
408404 :param (bool) show_hover: show county hover and centroid info
409405 :param (bool) show_state_data: reveals state boundary lines
410406 :param (dict) state_outline: dict of attributes of the state outline
@@ -416,8 +412,9 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
416412 https://plot.ly/python/reference/#scatter-marker-line for all valid
417413 params
418414 :param (dict) centroid_marker: dict of attributes of the centroid marker.
419- See https://plot.ly/python/reference/#scatter-marker for all valid
420- params
415+ The centroid markers are invisible by default and appear visible on
416+ selection. See https://plot.ly/python/reference/#scatter-marker for
417+ all valid params
421418 :param (bool) round_legend_values: automatically round the numbers that
422419 appear in the legend to the nearest integer.
423420 Default = False
@@ -587,9 +584,11 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
587584 county_outline = {'color' : 'rgb(0, 0, 0)' ,
588585 'width' : 0 }
589586 if not centroid_marker :
590- centroid_marker = {'size' : 2 ,
591- 'color' : 'rgb(255, 255, 255)' ,
592- 'opacity' : 0 }
587+ centroid_marker = {'size' : 3 , 'color' : 'white' , 'opacity' : 1 }
588+
589+ # ensure centroid markers appear on selection
590+ if 'opacity' not in centroid_marker :
591+ centroid_marker .update ({'opacity' : 1 })
593592
594593 if len (fips ) != len (values ):
595594 raise exceptions .PlotlyError (
@@ -802,19 +801,14 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
802801 text = centroid_text ,
803802 name = 'US Counties' ,
804803 mode = 'markers' ,
805- marker = centroid_marker ,
804+ marker = { 'color' : 'white' , 'opacity' : 0 } ,
806805 hoverinfo = 'text'
807806 )
808- if offline_mode :
809- centroids_on_select = dict (
810- selected = dict (
811- marker = dict (size = 2 , color = 'white' , opacity = 1 )
812- ),
813- unselected = dict (
814- marker = dict (opacity = 0 )
815- )
816- )
817- hover_points .update (centroids_on_select )
807+ centroids_on_select = dict (
808+ selected = dict (marker = centroid_marker ),
809+ unselected = dict (marker = dict (opacity = 0 ))
810+ )
811+ hover_points .update (centroids_on_select )
818812 plot_data .append (hover_points )
819813
820814 if show_state_data :
0 commit comments