Skip to content

Commit 5d58021

Browse files
author
Florent Chehab
committed
nan_fill_opacity parameter added
1 parent ba0c64c commit 5d58021

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

folium/folium.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ def fit_bounds(self, bounds, padding_top_left=None,
425425

426426
def choropleth(self, geo_data, data=None, columns=None, key_on=None,
427427
bins=6, fill_color='blue', nan_fill_color='#000000b4',
428-
fill_opacity=0.6, line_color='black', line_weight=1,
429-
line_opacity=1, name=None, legend_name='', topojson=None,
430-
reset=False, smooth_factor=None, highlight=None,
431-
**kwargs):
428+
fill_opacity=0.6, nan_fill_opacity=None, line_color='black',
429+
line_weight=1, line_opacity=1, name=None, legend_name='',
430+
topojson=None, reset=False, smooth_factor=None,
431+
highlight=None, **kwargs):
432432
"""
433433
Apply a GeoJSON overlay to the map.
434434
@@ -487,6 +487,8 @@ def choropleth(self, geo_data, data=None, columns=None, key_on=None,
487487
(which is black '#000000' at ~0.71 opacity 'b4').
488488
fill_opacity: float, default 0.6
489489
Area fill opacity, range 0-1.
490+
nan_fill_opacity: float, default fill_opacity
491+
Area fill opacity for nan or missing values, range 0-1.
490492
line_color: string, default 'black'
491493
GeoJSON geopath line color.
492494
line_weight: int, default 1
@@ -534,6 +536,9 @@ def choropleth(self, geo_data, data=None, columns=None, key_on=None,
534536
raise ValueError('Please pass a valid color brewer code to '
535537
'fill_local. See docstring for valid codes.')
536538

539+
if nan_fill_opacity is None:
540+
nan_fill_opacity = fill_opacity
541+
537542
if 'threshold_scale' in kwargs:
538543
if kwargs['threshold_scale'] is not None:
539544
bins = kwargs['threshold_scale']
@@ -594,13 +599,11 @@ def color_scale_fun(x):
594599
key_of_x = get_by_key(x, key_on)
595600

596601
if key_of_x not in color_data.keys():
597-
# 1: opacity is handled within nan_fill_color
598-
return nan_fill_color, 1
602+
return nan_fill_color, nan_fill_opacity
599603

600604
value_of_x = color_data[key_of_x]
601605
if np.isnan(value_of_x):
602-
# 1: opacity is handled within nan_fill_color
603-
return nan_fill_color, 1
606+
return nan_fill_color, nan_fill_opacity
604607

605608
color_idx = np.digitize(value_of_x, bin_edges, right=False) - 1
606609
return color_range[color_idx], fill_opacity

0 commit comments

Comments
 (0)