legend_scaler

folium.utilities.legend_scaler(legend_values, max_labels=10.0)

Downsamples the number of legend values so that there isn’t a collision of text on the legend colorbar (within reason). The colorbar seems to support ~10 entries as a maximum.

linear_gradient

folium.utilities.linear_gradient(hexList, nColors)

Given a list of hexcode values, will return a list of length nColors where the colors are linearly interpolated between the (r, g, b) tuples that are given.

Examples

>>> linear_gradient([(0, 0, 0), (255, 0, 0), (255, 255, 0)], 100)

color_brewer

folium.utilities.color_brewer(color_code, n=6)

Generate a colorbrewer color scheme of length ‘len’, type ‘scheme. Live examples can be seen at http://colorbrewer2.org/

split_six

folium.utilities.split_six(series=None)

Given a Pandas Series, get a domain of values from zero to the 90% quantile rounded to the nearest order-of-magnitude integer. For example, 2100 is rounded to 2000, 2790 to 3000.

Parameters:series (Pandas series, default None) –
Returns:
Return type:list

image_to_url

folium.utilities.image_to_url(image, colormap=None, origin='upper')

Infers the type of an image argument and transforms it into a URL.

Parameters:
  • image (string, file or array-like object) –
    • If string, it will be written directly in the output file.
    • If file, it’s content will be converted as embedded in the output file.
    • If array-like, it will be converted to PNG base64 string and embedded in the output.
  • origin (['upper' | 'lower'], optional, default 'upper') – Place the [0, 0] index of the array in the upper left or lower left corner of the axes.
  • colormap (callable, used only for mono image.) – Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)] for transforming a mono image into RGB. It must output iterables of length 3 or 4, with values between 0. and 1. Hint : you can use colormaps from matplotlib.cm.

write_png

folium.utilities.write_png(data, origin='upper', colormap=None)

Transform an array of data into a PNG string. This can be written to disk using binary I/O, or encoded using base64 for an inline PNG like this:

>>> png_str = write_png(array)
>>> "data:image/png;base64,"+png_str.encode('base64')

Inspired from http://stackoverflow.com/questions/902761/saving-a-numpy-array-as-an-image

Parameters:
  • data (numpy array or equivalent list-like object.) – Must be NxM (mono), NxMx3 (RGB) or NxMx4 (RGBA)
  • origin (['upper' | 'lower'], optional, default 'upper') – Place the [0,0] index of the array in the upper left or lower left corner of the axes.
  • colormap (callable, used only for mono image.) – Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)] for transforming a mono image into RGB. It must output iterables of length 3 or 4, with values between 0. and 1. Hint: you can use colormaps from matplotlib.cm.
Returns:

Return type:

PNG formatted byte string

_parse_size

folium.utilities._parse_size(value)