ColorMap

class folium.colormap.ColorMap(vmin=0.0, vmax=1.0, caption='')

A generic class for creating colormaps.

Parameters:TODO (docstring) –
__call__(x)

Provides the color corresponding to value x in the form of a string of hewadecimal values “#RRGGBB”.

render(**kwargs)

TODO: docstring

rgb_bytes_tuple(x)

Provides the color corresponding to value x in the form of a tuple (R,G,B) with int values between 0 and 255.

rgb_hex_str(x)

Provides the color corresponding to value x in the form of a string of hewadecimal values “#RRGGBB”.

rgba_bytes_tuple(x)

Provides the color corresponding to value x in the form of a tuple (R,G,B,A) with int values between 0 and 255.

rgba_floats_tuple(x)

This class has to be implemented for each class inheriting from Colormap. This has to be a function of the form float -> (float, float, float, float) describing for each input float x, the output color in RGBA format; Each output value being between 0 and 1.

LinearColormap

class folium.colormap.LinearColormap(colors, index=None, vmin=0.0, vmax=1.0, caption='')

Creates a ColorMap based on linear interpolation of a set of colors over a given index.

Parameters:
  • colors (list-like object) – The set of colors to be used for interpolation. Colors can be provided in the form: * tuples of int between 0 and 255 (e.g: (255,255,0) or (255, 255, 0, 255)) * tuples of floats between 0. and 1. (e.g: (1.,1.,0.) or (1., 1., 0., 1.)) * HTML-like string (e.g: “#ffff00) * a color name or shortcut (e.g: “y” or “yellow”)
  • index (list of floats, default None) – The values corresponding to each color. It has to be sorted, and have the same length as colors. If None, a regular grid between vmin and vmax is created.
  • vmin (float, default 0.) – The minimal value for the colormap. Values lower than vmin will be bound directly to colors[0].
  • vmax (float, default 1.) – The maximal value for the colormap. Values higher than vmax will be bound directly to colors[-1].
rgba_floats_tuple(x)

Provides the color corresponding to value x in the form of a tuple (R,G,B,A) with float values between 0. and 1.

scale(vmin=0.0, vmax=1.0)

Transforms the colorscale so that the minimal and maximal values fit the given parameters.

to_step(n=None, index=None, data=None, method=None, quantiles=None, round_method=None)

Splits the LinearColormap into a StepColormap.

Parameters:
  • n (int, default None) – The number of expected colors in the ouput StepColormap. This will be ignored if index is provided.
  • index (list of floats, default None) – The values corresponding to each color bounds. It has to be sorted. If None, a regular grid between vmin and vmax is created.
  • data (list of floats, default None) – A sample of data to adapt the color map to.
  • method (str, default 'linear') – The method used to create data-based colormap. It can be ‘linear’ for linear scale, ‘log’ for logarithmic, or ‘quant’ for data’s quantile-based scale.
  • quantiles (list of floats, default None) – Alternatively, you can provide explicitely the quantiles you want to use in the scale.
  • round_method (str, default None) – The method used to round thresholds. * If ‘int’, all values will be rounded to the nearest integer. * If ‘log10’, all values will be rounded to the nearest order-of-magnitude integer. For example, 2100 is rounded to 2000, 2790 to 3000.
Returns:

  • A StepColormap with n=len(index)-1 colors.
  • Examples
  • >> lc.to_step(n=12)
  • >> lc.to_step(index=[0, 2, 4, 6, 8, 10])
  • >> lc.to_step(data=some_list, n=12)
  • >> lc.to_step(data=some_list, n=12, method=’linear’)
  • >> lc.to_step(data=some_list, n=12, method=’log’)
  • >> lc.to_step(data=some_list, n=12, method=’quantiles’)
  • >> lc.to_step(data=some_list, quantiles=[0, 0.3, 0.7, 1])
  • >> lc.to_step(data=some_list, quantiles=[0, 0.3, 0.7, 1],
  • ... round_method=’log10’)

StepColormap

class folium.colormap.StepColormap(colors, index=None, vmin=0.0, vmax=1.0, caption='')

Creates a ColorMap based on linear interpolation of a set of colors over a given index.

Parameters:
  • colors (list-like object) – The set of colors to be used for interpolation. Colors can be provided in the form: * tuples of int between 0 and 255 (e.g: (255,255,0) or (255, 255, 0, 255)) * tuples of floats between 0. and 1. (e.g: (1.,1.,0.) or (1., 1., 0., 1.)) * HTML-like string (e.g: “#ffff00) * a color name or shortcut (e.g: “y” or “yellow”)
  • index (list of floats, default None) – The values corresponding to each color. It has to be sorted, and have the same length as colors. If None, a regular grid between vmin and vmax is created.
  • vmin (float, default 0.) – The minimal value for the colormap. Values lower than vmin will be bound directly to colors[0].
  • vmax (float, default 1.) – The maximal value for the colormap. Values higher than vmax will be bound directly to colors[-1].
rgba_floats_tuple(x)

Provides the color corresponding to value x in the form of a tuple (R,G,B,A) with float values between 0. and 1.

scale(vmin=0.0, vmax=1.0)

Transforms the colorscale so that the minimal and maximal values fit the given parameters.

to_linear(index=None)

Transforms the StepColormap into a LinearColormap.

Parameters:index (list of floats, default None) – The values corresponding to each color in the output colormap. It has to be sorted. If None, a regular grid between vmin and vmax is created.

linear

folium.colormap.linear

A class for hosting the list of built-in linear colormaps.