Skip to content

Commit 0b2b470

Browse files
author
Florent Chehab
committed
Cleaning docstring and color_scale_fun logic
1 parent 86069b2 commit 0b2b470

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

folium/folium.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,11 @@ def choropleth(self, geo_data, data=None, columns=None, key_on=None,
469469
start with 'feature' and be in JavaScript objection notation.
470470
Ex: 'feature.id' or 'feature.properties.statename'.
471471
threshold_scale: list, default None
472-
Data range for D3 threshold scale. Defaults to a linear scale of
473-
6 bins going from min(values) to max(values).
474-
Values are expected to be sorted.
472+
Defaults to a linear scale of 6 bins going from min(values)
473+
to max(values). Values that are outside of the threshold_scale
474+
domain will be mapped to the closest color bin
475+
(i.e. the first or last bin of the scale)
476+
The list is expected to be sorted.
475477
fill_color: string, default 'blue'
476478
Area fill color. Can pass a hex code, color name, or if you are
477479
binding data, one of the following color brewer palettes:
@@ -570,22 +572,21 @@ def get_by_key(obj, key):
570572

571573
def color_scale_fun(x):
572574
key_of_x = get_by_key(x, key_on)
573-
if key_of_x in color_data.keys():
574-
value_of_x = color_data[key_of_x]
575-
else:
576-
# The value is missing
577-
value_of_x = None
578-
579-
if value_of_x is None or np.isnan(value_of_x):
580-
# The value is missing or is deliberately nan
575+
576+
if key_of_x not in color_data.keys():
577+
return nan_fill_color
578+
579+
value_of_x = color_data[key_of_x]
580+
if np.isnan(value_of_x):
581581
return nan_fill_color
582-
else:
583-
color_idx = int(np.digitize(value_of_x, color_domain)) - 1
584-
# we consider that values outside the color domain
585-
# should be affected to the first (or last) color bin.
586-
color_idx = max(0, color_idx)
587-
color_idx = min(nb_bins-1, color_idx)
588-
return color_range[color_idx]
582+
583+
color_idx = int(np.digitize(value_of_x, color_domain)) - 1
584+
# we consider that values outside of the color domain
585+
# should be mapped to the first (or last) color bin.
586+
color_idx = max(0, color_idx)
587+
color_idx = min(nb_bins-1, color_idx)
588+
return color_range[color_idx]
589+
589590
else:
590591
def color_scale_fun(x):
591592
return fill_color
@@ -629,8 +630,6 @@ def highlight_function(x):
629630
color_scale = StepColormap(
630631
brewed,
631632
index=color_domain,
632-
vmin=color_domain[0],
633-
vmax=color_domain[-1],
634633
caption=legend_name,
635634
)
636635
self.add_child(color_scale)

0 commit comments

Comments
 (0)